File Access Rights

This seems to be the state-of-the-art way to change access rights on a file in PowerShell:

$colRights = [System.Security.AccessControl.FileSystemRights]“Read”

$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None

$objType =[System.Security.AccessControl.AccessControlType]::Allow

$objUser = New-Object System.Security.Principal.NTAccount(“domain\user”)

$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)

$objACL = Get-ACL “c:\testfile”
$objACL.RemoveAccessRuleAll($objACE)

Set-ACL “c:\testfile” $objACL

Funny… The unix version would be something like

chmod 600 /testfile

I… uh… I don’t know. I’m tired. I want to go home now.

One thought on “File Access Rights

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>