Advertisement
Dennisaa

remote file permissions

Mar 9th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .Synopsis
  3.    For 1 or more computers, for a given folder root, apply full permissions from
  4.    the root down
  5. .Description
  6.    Also see http://technet.microsoft.com/en-us/library/ff730951.aspx
  7.    $session = New-PSSession -ComputerName "jan-pc"
  8.    Enter-PSSession -Session $session
  9.    Get-ACL "C:\sandbox\PowerShell\artefacts\subFolder" | Format-List
  10.    Which returns eg
  11.    Path   : Microsoft.PowerShell.Core\FileSystem::C:\sandbox\PowerShell\artefacts\subFolder
  12.         Owner  : BUILTIN\Administrators
  13.         Group  : Jan-pc\denni_000
  14.         Access : BUILTIN\Administrators Allow  FullControl
  15.                  NT AUTHORITY\SYSTEM Allow  FullControl
  16.                 BUILTIN\Users Allow  ReadAndExecute, Synchronize
  17.                 NT AUTHORITY\Authenticated Users Allow  Modify, Synchronize
  18.                 NT AUTHORITY\Authenticated Users Allow  -536805
  19.         Audit  :
  20.         Sddl   : O:BAG:S-1-5-(snip)OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)
  21.  
  22. .Example
  23. #>
  24. function Set-FullFolderPermissions
  25. {
  26.     Param (
  27.         [Parameter(Mandatory=$true, Position=0)]
  28.         [string[]]
  29.         $ComputerName,
  30.         [Parameter(Mandatory=$true, Position=1)]
  31.         [string]
  32.         $FolderRoot
  33.     )
  34.     Begin {
  35.           $fileRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
  36.           $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
  37.           $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
  38.           $objType =[System.Security.AccessControl.AccessControlType]::Allow
  39.     }
  40.     Process {
  41.         foreach ($computer in $ComputerName) {
  42.           $cred = Get-Credential
  43.           Invoke-Command -ComputerName $computer -Credential $cred -ScriptBlock {
  44.                 $objUser = New-Object System.Security.Principal.NTAccount("BUILTIN\users")
  45.                 $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
  46.                 $objACL = Get-ACL "C:\TestFolder"
  47.                 $objACL.AddAccessRule($objACE)
  48.                 Set-ACL "C:\TestFolder" $objACL
  49.             }
  50.          }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement