Created
July 24, 2009 14:42
-
-
Save drusellers/154309 to your computer and use it in GitHub Desktop.
This file contains 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
function OnServer($serverName, $action) | |
{ | |
$currentServerName = [System.Environment]::MachineName | |
if($currentServerName -eq $serverName) | |
{ | |
Write-Host "On Server '$currentServerName'" | |
&$action | |
} | |
else | |
{ | |
Write-Host "Wrong Server '$currentServerName' - Expected '$serverName'" | |
} | |
} | |
function OnPath($path, $action) | |
{ | |
if([System.IO.Directory]::Exists($path)) | |
{ | |
Write-Host "On Path '$path'" | |
$global:path = $path | |
&$action | |
} | |
else | |
{ | |
Write-Host "The path '$path' doesn't exist" | |
} | |
} | |
function Grant($username, $permission) | |
{ | |
$path = $global:path | |
$acl = Get-Acl $path | |
$perm = $userName,$permission,"Allow" | |
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule $perm | |
$acl.SetAccessRule($ace) | |
$acl | Set-Acl | |
Write-Host "Granted '$username' '$permission' to '$path'" | |
} | |
#Read, Write, | |
OnServer "SELLERSD" { | |
OnPath "C:\Users\sellersd\Desktop\acl-test" { | |
Grant "TEST\ReynoldsR" "Read" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment