0
我正在寫一個函數,將從路徑A到ACL的ACL等同於路徑B(路徑A也可以是服務器B上的服務器A和路徑B)。幾乎所有內容都按預期工作,用戶被部署到目標路徑,但FileSystemRights不會被部署,即使我在函數中硬編碼「FullControl」。FileSystemRights沒有部署
我從來沒有在PowerShell中使用ACL合作過,並複製了我的大部分代碼從這裏:https://technet.microsoft.com/en-us/library/ff730951.aspx?f=255&MSPPError=-2147217396
爲什麼我FileSystemRights沒有得到部署?
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
}}
}}