Last active
August 29, 2015 14:22
-
-
Save r-plus/a59f1c73f62bdeea0c23 to your computer and use it in GitHub Desktop.
Add everyone read-only ACE to target path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add everyone read-only ACE to target path. | |
| # Doc: https://technet.microsoft.com/en-us/library/ff730951.aspx | |
| function Add-ReadOnlyACE([string]$path) | |
| { | |
| if (-not (Test-Path $path)) { return } | |
| # Create additionnal ACE. | |
| $colRights = [System.Security.AccessControl.FileSystemRights]"AppendData, ChangePermissions, CreateDirectories, CreateFiles, Delete, DeleteSubdirectoriesAndFiles, Write" | |
| $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit" | |
| $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None | |
| $objType =[System.Security.AccessControl.AccessControlType]::Deny | |
| $objUser = New-Object System.Security.Principal.NTAccount("Everyone") | |
| $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ` | |
| ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType) | |
| # Get then add ACE. | |
| $objACL = Get-Acl $path | |
| $objACL.AddAccessRule($objACE) | |
| Set-Acl $path -AclObject $objACL | |
| } | |
| Add-ReadOnlyACE "C:\test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment