有点奇怪的问题 - 我有以下脚本更改权限并且工作正常。但是,它在我目标的ROOT文件夹下面的文件夹中执行...但不会更改ROOT文件夹本身的权限!
那么,如何更改ROOT文件夹和子文件夹的权限......
$ROOT_FOLDER = "\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR"
Get-ChildItem $ROOT_FOLDER -Recurse | Where-Object {$_.PSIsContainer} | ForEach-Object {
$FullName = $_.FullName
$ACL_LIST = Get-Acl $FullName
$ACL_LIST.access | ForEach-Object {
if ($_.IdentityReference -eq "BFG\ACL-CHANGE-ALL-ROBS-UATW9GAR")
{
write-host $FullName -ForegroundColor white -NoNewline
$colRights1 = [System.Security.AccessControl.FileSystemRights]"Modify,DeleteSubdirectoriesAndFiles"
$permission = "BFG\ACL-CHANGE-ALL-ROBS-UATW9GAR",$colRights1,"ContainerInherit,ObjectInherit”,”None”,”Allow”
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$ACL_LIST.SetAccessRule($accessRule)
$ACL_LIST | Set-Acl $FullName
write-host " : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions"
}
}
}
输出我得到:
\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR\251 : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions
\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR\251\000 : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions
\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR\251\000\Adobe AIR : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions
\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR\251\000\SRV : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions
\\SERVER\d$\files\uatw9rar\W7_ADOBE_AIR\251\000\Adobe AIR\Versions : set with 'Modify,DeleteSubdirectoriesAndFiles' permissions
答案 0 :(得分:0)
Get-ChildItems
做了它在锡上的说法。它将遍历所有包含的项目,在您的情况-path
中提供-recurse
,并继续前进,直至遇到死胡同。
你可以做的是首先通过组合Get-Item
和Get-ChildItem
建立一个目录数组,如下所示:
$directories = @(Get-Item -path $ROOT_FOLDER | Where-object {$_.psIscontainer})
$directories += Get-ChildItem -path $ROOT_FOLDER -recurse | Where-object {$_.psIscontainer}
$directories | ForEach-Object {Do your stuff here}