Powershell 使用Append设置Acl
如何使用PowerShell将一个文件夹的ACL附加到另一个文件夹 我尝试了Powershell 使用Append设置Acl,powershell,acl,access-control,Powershell,Acl,Access Control,如何使用PowerShell将一个文件夹的ACL附加到另一个文件夹 我尝试了Get Acl和Set Acl,但是“当命令完成时,安全描述符..是相同的。” 这会导致下面我的\\dest\share失去dest\Administrators:Full Control和其他默认共享权限 Get Acl'\\source\share'| Set Acl'\\dest\share' 示例1:将安全描述符从一个文件复制到另一个文件 $DogACL = Get-Acl -Path "C:\Dog.txt"
Get Acl
和Set Acl
,但是“当命令完成时,安全描述符..是相同的。”
这会导致下面我的\\dest\share
失去dest\Administrators:Full Control
和其他默认共享权限
Get Acl'\\source\share'| Set Acl'\\dest\share'
示例1:将安全描述符从一个文件复制到另一个文件
$DogACL = Get-Acl -Path "C:\Dog.txt"
Set-Acl -Path "C:\Cat.txt" -AclObject $DogACL
这些命令从
将Dog.txt文件转换为Cat.txt文件的安全描述符。当
命令完成后,Dog.txt和Cat.txt的安全描述符
文件是相同的
如何将
\\source\share
的ACL附加到\\dest\share
中?如果要添加额外的ACL而不是替换它们,则必须在设置目标ACL之前对其进行修改
下面是一个在live shares上试用它之前,我将如何设置测试它的方法:
# Make folders and shares on the machine you'd like to test on
New-Item -Path C:\Users\TestUser\Documents\Share1 -Type Directory -Force
New-Item -Path C:\Users\TestUser\Documents\Share2 -Type Directory -Force
New-SmbShare -Path "C:\Users\TestUser\Documents\Share1" -Name SourceShare
New-SmbShare -Path "C:\Users\TestUser\Documents\Share2" -Name DestinationShare
现在,请花点时间手动更改共享上的ACL,以便在将其从源复制到目标时可以判断它是否有效。然后继续下面的步骤:
# Set network share path variables
$SourceShare = "\\GLaDOS\SourceShare"
$DestinationShare = "\\GLaDOS\DestinationShare"
# Set ACL variables
$SourceAcl = Get-Acl $SourceShare
$DestinationAcl = Get-Acl $DestinationShare
# Add all the source ACL's to the destination ACL
$SourceAcl.Access | foreach {$DestinationAcl.AddAccessRule($_)}
# Invoke the command on the computer using local path since network path does not seem to work
Invoke-Command -ComputerName GLaDOS -ScriptBlock {$LocalPath = (Get-SmbShare -Name DestinationShare).Path ; Set-Acl $LocalPath $Using:DestinationAcl}
显然,您需要分别用username和computername替换TestUser和GLaDOS
注意:在使用
Invoke命令之前,我尝试了一个不太复杂的选项,但出现了一个身份验证错误:
PS C:\> Set-Acl $DestinationShare $DestinationAcl
Set-Acl : Attempted to perform an unauthorized operation.
我还没弄明白那个。我应该拥有所需的所有权限