【发布时间】:2016-09-28 20:42:39
【问题描述】:
我可以接管所有权,然后将 acl 设置为文件夹吗?我有一个folders.txt 文件,其中有文件夹的位置。
例如:
D:\Dept\CC\NorthRiver\16-17\StaffAdministration
然后我在新建上一年文件夹结构,并将往年文件夹的权限和权限复制到新文件夹年份匹配文件夹中。由于文件夹的所有权,我遇到了一个问题。如果我不是所有者,我无法复制某些文件夹的权限,我会收到Set-ACL : The security identifier is not allowed to be the owner of this object. 有什么办法解决这个问题吗?
我尝试添加该行(将所有者更改为我,但也没有用):
get-item $currentFolder.Replace("16-17", "15-16") | set-owner -Account 'VDB-TST1\Administrators'
有没有人知道我可以如何做到这一点? 这是我的完整脚本:
Function Get-FileName{
[CmdletBinding()]
Param(
[String]$Filter = "|*.*",
[String]$InitialDirectory = "C:\")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $InitialDirectory
$OpenFileDialog.filter = $Filter
[void]$OpenFileDialog.ShowDialog()
$OpenFileDialog.filename
}
#Get and Set the ACL to the new years folder structure
foreach ($currentFolder in (GC (Get-FileName -InitialDirectory $env:USERPROFILE\Desktop -Filter "Text files (*.txt)|*.txt|All files (*.*)|*.*"))) {
md $currentFolder # Create Folder
get-item $currentFolder.Replace("16-17", "15-16") | set-owner -Account 'VDB-TST1\Administrators'
Get-ACL $currentFolder.Replace("16-17", "15-16") | Set-ACL $currentFolder
}
【问题讨论】:
标签: powershell