Guest User

Untitled

a guest
Apr 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. New-Item -Path "C:Homes" -name $username -ItemType Directory
  2.  
  3. $Rights = [System.Security.AccessControl.FileSystemRights]"FullControl"
  4.  
  5. $Inheritance = [System.Security.AccessControl.InheritanceFlags]::"ContainerInherit", "ObjectInherit"
  6.  
  7. $Propagation = [System.Security.AccessControl.PropagationFlags]::None
  8.  
  9. $AC =[System.Security.AccessControl.AccessControlType]::Allow
  10.  
  11. $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ($username, $Rights, $Inheritance, $Propagation, $AC)
  12.  
  13. $ACL = Get-Acl -Path "C:Homes$username"
  14. $ACL.SetAccessRuleProtection($True, $False)
  15.  
  16. $ACL.SetAccessRule($NewACL)
  17.  
  18. $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ("SYSTEM", $Rights, $Inheritance, $Propagation, $AC)
  19. $ACL.SetAccessRule($NewACL)
  20.  
  21. $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ("Administrators", $Rights, $Inheritance, $Propagation, $AC)
  22. $ACL.SetAccessRule($NewACL)
  23.  
  24. Set-Acl -Path "C:Homes$username" -AclObject $ACL
  25.  
  26. Set-ADUser -Identity $username -Replace @{HomeDirectory=$homeDir}
  27. Set-ADUser -Identity $username -Replace @{HomeDrive=$homeDrive}
Add Comment
Please, Sign In to add comment