当前有此脚本将报告顶部文件夹和子文件夹内的权限。我还需要它来报告所有文件。我已经安装了 Export-Excel 模块,以便它可以导出到 Excel 文件。
$FolderPath = Get-ChildItem -Directory -Path "E:\TEMP\" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Output += New-Object -TypeName PSObject -Property $Properties
}
}
$Output | Export-Excel E:\TEMP\Report.xlsx -TableName Permissions -AutoSize
预先感谢您提供的任何帮助。
由于您使用“-Directory”开关设置 $FolderPath 变量,因此您只能获取变量中的文件夹/目录。
您要么需要删除该开关,要么制作一份完整的代码副本,用新变量(例如 $Filepath)替换第 1 行
$Filepath = Get-ChildItem -File -Path "E:\TEMP" -Recurse -Force
然后迭代每个文件 ACL 对象,就像对文件夹所做的那样