Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Powershell脚本的权限继承_Windows_Powershell_Inheritance_Permissions_Subdirectory - Fatal编程技术网

Windows Powershell脚本的权限继承

Windows Powershell脚本的权限继承,windows,powershell,inheritance,permissions,subdirectory,Windows,Powershell,Inheritance,Permissions,Subdirectory,我正在尝试创建一个脚本,该脚本将传递子文件夹的继承 例如: C:/template has x y z permissions C:/template/test only has x permissions 我希望C:/template中的所有子文件夹和文件获得x y z权限 类似于罗伯特·普鲁斯特(Robert Prust)所做的(它不执行): 谢谢 Jonathan只需运行icacls“C:\template\*”/q/C/t/reset。没有比这更简单的了。这不起作用,它会将其重置为默认

我正在尝试创建一个脚本,该脚本将传递子文件夹的继承

例如:

C:/template has x y z permissions
C:/template/test only has x permissions
我希望C:/template中的所有子文件夹和文件获得x y z权限

类似于罗伯特·普鲁斯特(Robert Prust)所做的(它不执行):

谢谢


Jonathan

只需运行
icacls“C:\template\*”/q/C/t/reset
。没有比这更简单的了。

这不起作用,它会将其重置为默认值。例如:
C:/Template with x y z(z手动添加,x y为默认值)
当您运行命令时,它会将所有内容设置为默认值:
C:/Template x y
@ansgarwiechers@JonathanDavies我的错误。由于要将子元素的权限重置为
C:\template
上的权限,因此路径必须是
C:\template\*
。请参阅更新的答案。
$ACL = Get-Acl -Path C:\Template
$Folders = Get-ChildItem -Recurse -Path "C:\new_perm" -Filter 'Subfolder*' | Select-Object -ExpandProperty FullName
foreach ($Folder in $Folders) {
   # write the variables found - check if the folder path is correct
   # Write-Output "This foldername is $Folder"
   # convert foldername to a icacls approved path
   $icacls = "$Folder\*"
   # check if the icacls path is correct
   # Write-Output "icacls path is $icacls"
   #set the ACL required on the folder
   Set-ACL -Path $Folder -AclObject $ACL
   # replace all child permissions for the folder
   icacls $icacls /q /c /t /reset
}