You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求修改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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 03:42:26