Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- New-Item -Path "C:Homes" -name $username -ItemType Directory
- $Rights = [System.Security.AccessControl.FileSystemRights]"FullControl"
- $Inheritance = [System.Security.AccessControl.InheritanceFlags]::"ContainerInherit", "ObjectInherit"
- $Propagation = [System.Security.AccessControl.PropagationFlags]::None
- $AC =[System.Security.AccessControl.AccessControlType]::Allow
- $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ($username, $Rights, $Inheritance, $Propagation, $AC)
- $ACL = Get-Acl -Path "C:Homes$username"
- $ACL.SetAccessRuleProtection($True, $False)
- $ACL.SetAccessRule($NewACL)
- $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ("SYSTEM", $Rights, $Inheritance, $Propagation, $AC)
- $ACL.SetAccessRule($NewACL)
- $NewACL = New-Object System.Security.AccessControl.FileSystemAccessRule ("Administrators", $Rights, $Inheritance, $Propagation, $AC)
- $ACL.SetAccessRule($NewACL)
- Set-Acl -Path "C:Homes$username" -AclObject $ACL
- Set-ADUser -Identity $username -Replace @{HomeDirectory=$homeDir}
- Set-ADUser -Identity $username -Replace @{HomeDrive=$homeDrive}
Add Comment
Please, Sign In to add comment