我很难让Get-Acl
在UNC路径上工作以获取目录和所有底层文件和目录的共享权限。
我使用的代码如下所示:
$OutFile = "C:\Users\xxxx\Desktop\Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags,FileSystemRights"
del $OutFile
Add-Content -Value $Header -Path $OutFile
$RootPath = "\\intranet\sites\folder1\folder2\target-folder-as-root"
$Folders = dir $RootPath -Recurse
#| where {$_.psiscontainer -eq $true}-recurse
foreach ($Folder in $Folders) {
$ACLs = Get-Acl $Folder.Fullname | ForEach-Object { $_.Access }
foreach ($ACL in $ACLs) {
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," +
$ACL.AccessControlType + "," + $ACL.IsInherited + "," +
$ACL.InheritanceFlags + "," + $ACL.PropagationFlags + "," +
$ACL.FileSystemRights
Add-Content -Value $OutInfo -Path $OutFile
}
}
没有考虑到这可能导致的文件名大小限制问题,我收到以下错误:
Get-Acl : Method failed with unexpected error code 1. At C:\Users\xxxx\Documents\ntfs_permissions.ps1:12 char:10 + $ACLs = Get-Acl $Folder.Fullname | ForEach-Object { $_.Access } + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-Acl], InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetAclCommand
我找到有关使用UNC路径列出共享驱动器上的共享权限的文档(我不想从根开始列出权限,但只从子文件夹开始)非常有限。
答案 0 :(得分:0)
尝试使用:$ACLs = (Get-Acl $Folder.fullname).Access
而不是:$ACLs = Get-Acl $Folder.Fullname | ForEach-Object { $_.Access }