请求修改PowerShell脚本:新增文件权限报告并导出至Excel
修改后的PowerShell脚本(包含文件与文件夹权限报告)
以下是调整后的脚本,可同时生成指定目录下所有文件和文件夹的权限报告:
$Items = Get-ChildItem -Path "E:\TEMP\" -Recurse -Force $Output = @() ForEach ($Item in $Items) { $Acl = Get-Acl -Path $Item.FullName ForEach ($Access in $Acl.Access) { $Properties = [ordered]@{ 'ItemPath' = $Item.FullName 'ItemType' = if ($Item.PSIsContainer) { 'Folder' } else { 'File' } '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
关键修改点:
- 移除
Get-ChildItem的-Directory参数,使其同时遍历文件和子文件夹 - 新增
ItemType字段,通过$Item.PSIsContainer属性区分当前项是文件还是文件夹 - 将原
FolderName字段重命名为ItemPath,让字段名更贴合实际内容
内容的提问来源于stack exchange,提问作者SuperZee
相关产品推荐
相关产品推荐

