Recently wrote a simple function to add permission to filesystem resources. It defaults to modify permissions, but can also be another basic permission for instance: Read, Write or FullControl.
function fnAddFilesystemPermissions()
{
param (
[string]$sPath,
[string]$sUserName,
[string]$sPermission = "Modify"
)
# Add write permissions to a file using powershell...
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($sUserName,$sPermission,"Allow")
$acl = Get-ACL -Path $sPath
$acl.SetAccessRule($accessRule)
$acl | Set-Acl -Path $sPath
# Return permissions...
return (Get-ACL -Path $sPath).Access | Format-Table
}
PS> fnAddFilesystemPermissions -sPath “C:\Path\To\Resource” -sUserName “User-Principle-Name” [-sPermission “FullControl“]