Advertisement
private775

PS: grant user access to folders

Jan 28th, 2020
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $usersid = New-Object System.Security.Principal.Ntaccount("ADDOMAIN\ad_user")
  3. $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($usersid,[System.Security.AccessControl.FileSystemRights]::ReadAndExecute, [System.Security.AccessControl.AccessControlType]::Allow)
  4.  
  5. Get-ChildItem -Recurse -Directory . | % {
  6.     Write-Host "Setting rights to $($_.FullName)"
  7.     $fld = $_.FullName
  8.     $acl = get-acl $fld
  9.     $acl.PurgeAccessRules($usersid)
  10.     $acl.SetAccessRule($accessRule)
  11.     $acl | Set-Acl $fld
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement