Skip to content

Instantly share code, notes, and snippets.

@seanosullivanuk
Created December 12, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seanosullivanuk/ce90c4d5bc0e0de8442bc7afb1cb23e8 to your computer and use it in GitHub Desktop.
Save seanosullivanuk/ce90c4d5bc0e0de8442bc7afb1cb23e8 to your computer and use it in GitHub Desktop.
Create a folder, add a hidden share, set NTFS permissions and disable inheritance
#Install-Module -Name NTFSSecurity
$user = "test.user"
$domain = "contoso"
# Create the folder and share it
New-Item -Path D:\Employees\$user -ItemType directory
New-SmbShare -Name "$user$" -Path "D:\Employees\$user" -ChangeAccess "$domain\$user"
# Set file permissions (change to taste)
Get-Item D:\Employees\$user | Add-NTFSAccess -Account $domain\$user -AccessRights Modify
Get-Item D:\Employees\$user | Add-NTFSAccess -Account $domain\grp-admins -AccessRights FullControl
# Copy the existing ACL, disable inheritance and copy the ACL back
$acl = Get-ACL -Path D:\Employees\$user
$acl.SetAccessRuleProtection($True, $True)
Set-Acl -Path D:\Employees\$user -AclObject $acl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment