是否可以编写一个powershell脚本来创建我在文本文件中的文件夹结构,如下所示:
D:\Dept\AD\16-17\Audit\FIR
D:\Dept\AD\16-17\Budget\Working
D:\Dept\AD\16-17\Budget\Final
D:\Dept\AD\16-17\Correspondence\MediaReleases
D:\Dept\AD\16-17\Correspondence\DL
D:\Dept\AD\16-17\Correspondence\HF
D:\Dept\AD\16-17\Correspondence\Tax
D:\Dept\CC\QualityAssurance\16-17\Audit\FIR
D:\Dept\CC\QualityAssurance\16-17\Budget\Working
D:\Dept\CC\QualityAssurance\16-17\Budget\Final
但是要拥有从前一年已经存在的权限和权限吗?文件夹结构哪一年是唯一的区别?
D:\Dept\AD\15-16\Audit\FIR
D:\Dept\AD\15-16\Budget\Working
D:\Dept\AD\15-16\Budget\Final
D:\Dept\AD\15-16\Correspondence\MediaReleases
D:\Dept\AD\15-16\Correspondence\DL
D:\Dept\AD\15-16\Correspondence\HF
D:\Dept\AD\15-16\Correspondence\Tax
D:\Dept\CC\QualityAssurance\15-16\Audit\FIR
D:\Dept\CC\QualityAssurance\15-16\Budget\Working
D:\Dept\CC\QualityAssurance\15-16\Budget\Final
我只是想创建新的一年,但保持所有权利和权限与去年相同。上一年还有其他文件所以我试图让txt.file创建文件夹,然后以某种方式抓住前几年的权利和写入新文件夹的权限。这可能吗?
@sapl收到两个错误:
Directory: D:\Dept\DC\16-17\OSA
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 9/27/2016 4:45 PM OperationalReports
Set-ACL : The security identifier is not allowed to be the owner of this object.
At line:19 char:56
+ Get-ACL $currentFolder.Replace("16-17", "15-16") | Set-ACL $currentFolder
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (D:\Dept\DC\16-17\OSA\OperationalReports:String) [Set-Acl], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
Directory: D:\Dept\CC\NorthRiver\16-17\StaffAdministration
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 9/27/2016 4:45 PM CFCA
Set-ACL : The security identifier is not allowed to be the owner of this object.
At line:19 char:56
+ Get-ACL $currentFolder.Replace("16-17", "15-16") | Set-ACL $currentFolder
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (D:\Dept\CC\Nort...nistration\CFCA:String) [Set-Acl], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
答案 0 :(得分:1)
让我们假设您有一个文件" folders.txt"它包含所需的文件夹,每行一个,你可以这样做:
foreach ($currentFolder in (Get-Content .\folders.txt)) {
md $currentFolder # Create Folder
(Get-Item $currentFolder.Replace("16-17", "15-16")).GetAccessControl("Access") | Set-ACL $currentFolder
}
请确保您在高架PowerShell控制台中运行它("以管理员身份运行")。
希望能帮到你