我使用一个脚本将 ACL 从一个系统导入到 csv 中,并使用另一个脚本读取 csv、创建文件夹结构并将权限应用到新系统。由于安全限制,系统不可能相互连接,因此不能选择 robocopy。
正在创建新的文件夹结构,但 ACL 未应用,并且出现错误。
以下是测试 csv 的示例:
FolderName,FolderPath,IdentityReference,FileSystemRights,InheritanceFlag
user1,DEEPP\Working\user1,AD\user1,Modify,"ContainerInherit, ObjectInherit"
user2,DEEPP\Working\user2,AD\user2,Modify,"ContainerInherit, ObjectInherit"
以下是读取 csv 并设置 ACL 的测试脚本。单步执行,直到底部的 Set-ACL 行为止,我没有收到任何错误。
#Create folders and apply AD permissions
#Note: Remove drive letter in FolderPath column of csv file (ex, F:\); remove non-AD user rows
# Location Where your folders are to be created
$RootDir = "C:\Users\TR\Documents\Scripts\ACL"
Set-Location "$RootDir"
# Import CSV file from location
$Folders = Import-Csv "$RootDir\ACLs_Proj-2023-01-25.csv"
$FolderPath = $Folder.FolderPath
# Create Folders from FolderPath column in csv; set ACL
ForEach ($Folder in $Folders)
{
$a = Test-Path $RootDir\$FolderPath #{continue} #{Write-Verbose "Folder: $Path Already Exists"}
if ($a -eq $false) {
New-Item $FolderPath -type directory
}
$IdentityReference = $Folder.IdentityReference
$FileSystemRights = $Folder.FileSystemRights
$InheritanceFlag = "ContainerInherit"
$PropagationFlag = "None"
$AccessControlType = "Allow"
#New-Object System.Security.AccessControl.FileSystemAccessRule('IdentityReference','FileSystemRights','InheritanceFlags','PropagationFlags','AccessControlType')
$New_ACL = New-Object Security.AccessControl.FileSystemAccessRule $IdentityReference, $FileSystemRights, $InheritanceFlag, $PropagationFlag, $AccessControlType
Set-Acl -Path "$RootDir\$FolderPath" -AclObject $New_ACL -WhatIf
}
来自 Set-ACL 行的错误:
Set-Acl : AclObject
At line:1 char:1
+ Set-Acl -Path "$RootDir\$FolderPath" -AclObject $New_ACL -WhatIf
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.Security...ystemAccessRule:FileSystemAccessRule) [Set-Acl], ArgumentException
+ FullyQualifiedErrorId : SetAcl_AclObject,Microsoft.PowerShell.Commands.SetAclCommand
如果我单独输入 $New_ACL,我得到的大部分是单个条目的预期输出:
FileSystemRights : Modify, Synchronize
AccessControlType : Allow
IdentityReference : AD\user2
IsInherited : False
InheritanceFlags : ContainerInherit
PropagationFlags : None
“主要”是因为,如 csv 示例中所示,“Synchronize”不在我的 csv 文件的 FileSystemRights 列中。仅键入 $FileSystemRights 只会提供预期的修改值。
同步条目是否混淆了我糟糕的脚本,或者我搞砸了一些不同的东西?如果是同步,我该如何摆脱它?我的理解是,如果没有列出,它将默认应用。
Thanks!