Skip to content

Instantly share code, notes, and snippets.

@drusellers
Created July 24, 2009 14:42
Show Gist options
  • Save drusellers/154309 to your computer and use it in GitHub Desktop.
Save drusellers/154309 to your computer and use it in GitHub Desktop.
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