2016-07-26 5 views
0

Ich schreibe eine Funktion zum Gleichsetzen einer ACL von Pfad A zu Pfad B (Pfad A kann auch ein Server A und Pfad B auf Server B sein). Fast alles funktioniert wie erwartet, der Benutzer wird auf den Zielpfad deployed, aber die FileSystemRights werden nicht implementiert, obwohl ich "FullControl" in der Funktion fest codiert habe.FileSystemRights werden nicht bereitgestellt

Ich arbeitete nie mit ACLs in Powershell vor und von hier aus den meisten meinem Code kopiert: https://technet.microsoft.com/en-us/library/ff730951.aspx?f=255&MSPPError=-2147217396

Warum zum Einsatz zu tun bekommen meine FileSystemRights nicht?

Process { 
# get ACL from source path 
    $gacl = get-acl $SourcePath | select -ExpandProperty Access | % { 
    $ErrorActionPreference = "SilentlyContinue" 
    [string]$user = ($_.IdentityReference).Value.split('\')[1] 
    [string]$AccessType = $_.AccessControlType 
    $FSRights = $_.FileSystemRights 

    if (!$user) { Write-Warning "User not found. Skipping ACL settings for this user. Username: $(($_.IdentityReference).Value)`n"} 
    else{ 
    # Create ACL Object 
    $colRights = [System.Security.AccessControl.FileSystemRights]"FullControl" 
    $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None 
    $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None 
    $objType =[System.Security.AccessControl.AccessControlType]$AccessType 
    $objUser = New-Object System.Security.Principal.NTAccount($user) 
    $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType) 

    # Set the ACL 
    Write-Host "Setting ACL for User: $User on $DestinationPath" -ForegroundColor Green 
    $objACL = get-acl $DestinationPath 
    $ErrorActionPreference = "Stop" 
    Try { 
     $objACL.AddAccessRule($objACE) 
     $sacl = set-acl $DestinationPath $objACL 
     Write-Host "Success!`n" -ForegroundColor Green 
    } Catch { 
     Write-Host "Failed! ErrorMessage:" -ForegroundColor Red 
     $_.Exception.Message 
    }} 
}} 

Antwort

0

Ich gab dies auf und beschloss, nur ein Modul zu verwenden, das den Trick für mich tut. Ich habe das folgende Modul verwendet: https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85

und das ist die Endfunktion. sehr einfach:

function Equate-ACL { 
param(
    [Parameter(Mandatory=$true,Position=0)] 
    [string]$SourcePath, 
    [Parameter(Mandatory=$true,Position=1)] 
    [string]$DestinationPath 
) 
    if(!(get-module NTFSSecurity)) { import-module NTFSSecurity } 
    $ErrorActionPreference = "Stop" 
    Try { 
     $SourcePath | Get-NTFSAccess | Add-NTFSAccess $DestinationPath 
    } Catch { 
     Write-Warning "Konnte ACL von $Sourcepath nicht auf $Destinationpath setzen." 
    } 
}