Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PowerShell Query

PowerShell Query

Scheduled Pinned Locked Moved C#
csharpphpdatabasecomwindows-admin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin McFarlane
    wrote on last edited by
    #1

    I know this is not C# but I figure there's more likely to be people in this forum that have played with PowerShell. I've been experimenting with a couple of scripts to set folder permissions and I'm getting nowhere fast. I've tried this from here http://chrisfederico.wordpress.com/2008/02/01/setting-acl-on-a-file-or-directory-in-powershell/[^]: $acl = Get-Acl c:\temp $permission = "domain\user","FullControl","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $acl | Set-Acl c:\temp and this from here http://technet.microsoft.com/en-us/magazine/cc194419.aspx[^]: #ChangeACL.ps1 $Right="FullControl" #The possible values for Rights are # ListDirectory, ReadData, WriteData # CreateFiles, CreateDirectories, AppendData # ReadExtendedAttributes, WriteExtendedAttributes, Traverse # ExecuteFile, DeleteSubdirectoriesAndFiles, ReadAttributes # WriteAttributes, Write, Delete # ReadPermissions, Read, ReadAndExecute # Modify, ChangePermissions, TakeOwnership # Synchronize, FullControl $StartingDir=Read-Host "What directory do you want to start at?" $Principal=Read-Host "What security principal do you want to grant" ` "$Right to? `n Use format domain\username or domain\group" #define a new access rule. #note that the $rule line has been artificially broken for print purposes. #it needs to be one line. the online version of the script is properly #formatted. $rule=new-object System.Security.AccessControl.FileSystemAccessRule ($Principal,$Right,"Allow") foreach ($file in $(Get-ChildItem $StartingDir -recurse)) { $acl=get-acl $file.FullName #Add this access rule to the ACL $acl.SetAccessRule($rule) #Write the changes to the object set-acl $File.Fullname $acl } For the second one I get this error when trying to apply it to an inetpub folder: Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated." At C:\Documents and Settings\kmcfarlane\My Documents\Development\ChangeACL.ps1:29 char:21 + $acl.SetAccessRule( <<<< $ru

    C 1 Reply Last reply
    0
    • K Kevin McFarlane

      I know this is not C# but I figure there's more likely to be people in this forum that have played with PowerShell. I've been experimenting with a couple of scripts to set folder permissions and I'm getting nowhere fast. I've tried this from here http://chrisfederico.wordpress.com/2008/02/01/setting-acl-on-a-file-or-directory-in-powershell/[^]: $acl = Get-Acl c:\temp $permission = "domain\user","FullControl","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $acl | Set-Acl c:\temp and this from here http://technet.microsoft.com/en-us/magazine/cc194419.aspx[^]: #ChangeACL.ps1 $Right="FullControl" #The possible values for Rights are # ListDirectory, ReadData, WriteData # CreateFiles, CreateDirectories, AppendData # ReadExtendedAttributes, WriteExtendedAttributes, Traverse # ExecuteFile, DeleteSubdirectoriesAndFiles, ReadAttributes # WriteAttributes, Write, Delete # ReadPermissions, Read, ReadAndExecute # Modify, ChangePermissions, TakeOwnership # Synchronize, FullControl $StartingDir=Read-Host "What directory do you want to start at?" $Principal=Read-Host "What security principal do you want to grant" ` "$Right to? `n Use format domain\username or domain\group" #define a new access rule. #note that the $rule line has been artificially broken for print purposes. #it needs to be one line. the online version of the script is properly #formatted. $rule=new-object System.Security.AccessControl.FileSystemAccessRule ($Principal,$Right,"Allow") foreach ($file in $(Get-ChildItem $StartingDir -recurse)) { $acl=get-acl $file.FullName #Add this access rule to the ACL $acl.SetAccessRule($rule) #Write the changes to the object set-acl $File.Fullname $acl } For the second one I get this error when trying to apply it to an inetpub folder: Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated." At C:\Documents and Settings\kmcfarlane\My Documents\Development\ChangeACL.ps1:29 char:21 + $acl.SetAccessRule( <<<< $ru

      C Offline
      C Offline
      ChrisKo 0
      wrote on last edited by
      #2

      This would probably be a better question in the Operating System/ Sysadmin forum as I think there's probably more PowerShell users there.

      K 1 Reply Last reply
      0
      • C ChrisKo 0

        This would probably be a better question in the Operating System/ Sysadmin forum as I think there's probably more PowerShell users there.

        K Offline
        K Offline
        Kevin McFarlane
        wrote on last edited by
        #3

        There are more eyes in this forum and nothing turned up when I did a search on PowerShell in that forum, so I thought I'd try here.

        Kevin

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups