Skip to content

Instantly share code, notes, and snippets.

@pcrockett-pathway
Created February 4, 2020 14:02
Show Gist options
  • Save pcrockett-pathway/36480ce5a8af1eed248813733c88222c to your computer and use it in GitHub Desktop.
Save pcrockett-pathway/36480ce5a8af1eed248813733c88222c to your computer and use it in GitHub Desktop.
Create a directory and lock down permissions so only the current user has access to it
New-Item -ItemType Directory $configDir | Out-Null
$acl = Get-Acl $configDir
$acl.SetAccessRuleProtection($True, $False) # Clear all access rules, disable permission inheritance
$currentUser = [Security.Principal.NTAccount]::new($env:USERNAME)
$acl.SetOwner($currentUser)
$accessRule = [Security.AccessControl.FileSystemAccessRule]::new($currentUser, "FullControl", "Allow")
$acl.SetAccessRule($accessRule)
Set-Acl -Path $configDir -AclObject $acl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment