Skip to content

Instantly share code, notes, and snippets.

@chrisATautomatemystuff
Created February 8, 2019 16:26
Show Gist options
  • Save chrisATautomatemystuff/45b3d80f33a6bc1d312356213ae26470 to your computer and use it in GitHub Desktop.
Save chrisATautomatemystuff/45b3d80f33a6bc1d312356213ae26470 to your computer and use it in GitHub Desktop.
#CREATE HOME DIRECTORY
New-Item -Path $homeDirectory -ItemType Directory -Force
#APPLY PERMISSIONS TO HOME FOLDER
$identityReference = $domainName + '\' + $samAccountName
$fileSystemAccessRights = [System.Security.AccessControl.FileSystemRights]::Modify
$inheritanceFlags = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$propagationFlags = [System.Security.AccessControl.PropagationFlags]::None
$accessControl = [System.Security.AccessControl.AccessControlType]::Allow
$accessRuleSplat = $identityReference, $fileSystemAccessRights, $inheritanceFlags, $propagationFlags, $accessControl
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $accessRuleSplat
$homeDirectoryACL = Get-Acl $homeDirectory
$homeDirectoryACL.AddAccessRule($accessRule)
Set-Acl -Path $homeDirectory -AclObject $homeDirectoryACL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment