Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Set-ACL, FileSystemRights werden nicht gesetzt

$
0
0

Ich möchte gerne von einem Pfad auf Server A die ACL kopieren und auf einem Pfad auf Server B einfügen. Dafür habe ich eine PowerShell function geschrieben.

Erst hatte ich etwas rudimentäres probiert in diesem stil get-acl C:\serverA\inetpub | set-acl D:\serverB\inetpubDas kann jedoch nicht funktionieren, da "IUSR, IISAPPPOOL virtual accounts etc. are all local to the machine's Security Account Manager database. They don't exist across multiple servers."

Deshalb schreibe ich mir in meiner Function nun alles raus was get-acl outputet. Mein Problem ist nun, dass die FileSystemRights einfach nicht übernommen werden. Ich habe es auch mal mit 2 lokalen Pfaden auf meinem C:\ probiert, auch dort werden die FileSystemRights nicht übernommen. Der User wird aber erstellt in der ACL, jedoch ohne Berechtigung. (Bsp, auf Server A Pfad X hat IUSR "Read, Write" Berechtigung, auf Server B Pfad Y hat der User noch keine Berechtigung, er wird nun hinzugefügt, das "Read, Write" wird jedoch nicht deployed)

Hier der Code:

function Equate-ACL {
param(
    [Parameter(Mandatory=$true,Position=0)]
    [string]$SourcePath,
    [Parameter(Mandatory=$true,Position=1)]
    [string]$DestinationPath
)
Begin {
    # Check if path exists and if access rights are correct
    if(!(Test-Path $SourcePath)) {
    Throw "Source Path does not exist or you don't have access rights."
    }
    if(!(Test-Path $DestinationPath)) {
    Throw "Destination Path does not exist or you don't have access rights."
    }
}
Process {
# get ACL from source path
    $gacl = get-acl $SourcePath | select -ExpandProperty Access | % {
    $ErrorActionPreference = "SilentlyContinue"
    [string]$user = ($_.IdentityReference).Value.split('\')[1]
    $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]$FSRights
    $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)
        $objACL | set-acl $DestinationPath
        Write-Host "Success!`n" -ForegroundColor Green
    } Catch {
        Write-Host "Failed! ErrorMessage:" -ForegroundColor Red
        $_.Exception.Message
    }}
}}}

Ich habe ernsthaft das Gefühl das ich hier Pionier-Arbeit leiste, da mir Google, Stackoverflow etc. keine Antwort auf meine Frage geben können. Das Technet ist also mein "Last Resort"

Danke und Grüsse

Simon


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>