1

This script was designed to make application of permissions to a new server much easier. It is not doing that currently :(

For some reason it works just fine on my Win 8 machine, where I made it. When I run it on the target machine, a 2008 R2 server, it just hangs on the first directory.

Not sure if PS version matters too much between v3 and v4 - script is fairly simple: - Windows Server 2008 R2 box is PowerShell v3 - Windows 8 box is PowerShell v4

Anyone know why that might be?

$csvFile = Read-Host "path to the CSV file with permissions"
$csv = Import-Csv $csvFile

Write-Host "Imported CSV File"

function applyPermissions {
    Param(
        [string]$Permission,
        [string]$Group,
        [string]$Dir,
        [bool]$Enclosed
    )

    if ($Enclosed) {
        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($Group,$Permission,"ObjectInherit, ContainerInherit","None","Allow")
        $Dir = $Dir.Replace("\*","")
        $acl = Get-Acl $Dir
        $acl.SetAccessRule($rule)
        Set-Acl $Dir $acl
    }
    else {
        $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($Group,$Permission,"ObjectInherit","NoPropagateInherit","Allow")
        $acl = Get-Acl $Dir
        $acl.SetAccessRule($rule)
        Set-Acl $Dir $acl
    }
}

foreach ($r in $csv) {
    Write-Host "Processing: $r"

    $perm = $r.Permission
    $grp = $r.Group
    $dr = $r.Path

    # enclosed needs to apply recursively
    $enc = $false
    if($dr -match "\*") { $enc = $true } else { $enc = $false }

    if ($perm -eq "ReadWrite") {
        applyPermissions  -Permission "ReadAndExecute, Write" -Group $grp -Dir $dr -Enclosed $enc
    }
    else {
        applyPermissions -Permission $perm -Group $grp -Dir $dr -Enclosed $enc
    }
}

EDIT:

  • After adding in some breakpoints on ISE I can see it gets caught at the Set-Acl portion in the applyPermissions function

  • There is seemingly no output in eventvwr relating to any issue / cause for powershell hanging on this command

johnnygear
  • 83
  • 1
  • 2
  • 8
  • Funny thing. I just tried to run this manually from PowerShell (As Domain Admin), and it still hangs on Set-Acl – johnnygear Apr 01 '14 at 03:31
  • Thought it might be an issue that the local Administrator account was the folder owner, so I logged in as the local admin, and Set-Acl still hangs. Also changed owner to the domain admin and tried again; Set-Acl still hangs.. – johnnygear Apr 01 '14 at 03:45

0 Answers0