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 Comment

  1. Raina
    Posted October 5, 2009 at 22:32 | Permalink

    I love it when you talk technical ;)

Post a Comment

Your email is never shared. Required fields are marked *

*
*