2015-06-28 13 views
0

我試圖做一個函數,將設置ACL權限,所有的數據來自XML作爲字符串,我沒有厭倦與繼承部分。與此代碼...當只使用一個繼承標誌ACL權限,從字符串值的多重繼承

$workingPermissions = Get-Acl $target 
       $acRights = [System.Security.AccessControl.FileSystemRights]$rights 
       $acInheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::$inheritance 
       $acPropagationFlag = [System.Security.AccessControl.PropagationFlags]::$propagation 
       $acType =[System.Security.AccessControl.AccessControlType]::Allow 
       $acUser = New-Object System.Security.Principal.NTAccount($principal) 
       $acEntry = New-Object System.Security.AccessControl.FileSystemAccessRule ($acUser, $acRights, $acInheritanceFlag, $acPropagationFlag, $acType) 

一切正常,但是當$繼承=「ContainerInherit,ObjectInherit」失敗。 $權利是以同樣的方式構建的,但我的理解是,無論出於什麼原因,繼承(和傳播?)的行爲都不一樣。 幾年前我發現了this thread,並且我沒有看到基於-bor的解決方案將允許任何基於字符串的輸入。事實上,我根本不理解它,因爲它看起來像$是隻是被設置爲一個枚舉,其中當然包含兩個$ flag設置的枚舉。 無論如何,希望有人能夠提供我自己的代碼所需的東西,也許我也會提供鏈接解決方案中真正發生的事情。

回答

1

離開繁殖的標誌爲無,

試試這個,它爲我工作

$SAMAccountName = "SamAccountName" ## Type your User/Group SamAccountName 
$Rights = "ReadAndExecute" 
$InheritanceFlag = @("ContainerInherit","ObjectInherit") 
$PropagationFlag = "None" 
$AccessType = "Allow" 

$NTAccount = [System.Security.Principal.NTAccount]($SAMAccountName) 
$IdentityReference = $NTAccount.Translate([System.Security.Principal.SecurityIdentifier]) 
$AccessRights = [System.Security.AccessControl.FileSystemRights] $Rights 
$InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]$InheritanceFlag 
$PropagationFlags = [System.Security.AccessControl.PropagationFlags]$PropagationFlag 
$Type = [System.Security.AccessControl.AccessControlType]$AccessType 
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($IdentityReference, $AccessRights, $InheritanceFlags,$PropagationFlags,$Type) 
$ACL = Get-Acl $Folder 
$ACL.AddAccessRule($AccessRule) 
Set-Acl -Path $Folder -AclObject $ACL 
+0

黨,怎麼就我錯過了,它需要一個數組。當然,爲什麼權利使用字符串,但繼承需要一個數組?無論如何...有一點 - 更換和.split我有我的人類可讀的字符串轉換爲一個數組,我走的比賽。謝謝! – Gordon