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

PowerShell导出文件夹权限时输出System.Object[]问题咨询

问题修复方案

问题根因

$Access.FileSystemRights 是 FileSystemRights 位域枚举类型,当权限为多个枚举值的组合时,PowerShell会将其识别为数组对象,CSV导出逻辑无法直接序列化数组内容,只会输出对应的类型名 System.Object[]。

修复方法

只需将Properties中Permissions字段的取值转换为字符串类型即可,两种常用转换方式可选:

  • 直接转成权限组合的可读字符串:使用ToString()方法
  • 转成逗号分隔的独立权限项列表:使用-join操作符拼接

修复后完整脚本

$FolderPath = dir -Directory -Path "\\fs1\Shared" -Recurse -Force
$Report = @()
Foreach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    foreach ($Access in $acl.Access)
        {
            $Properties = [ordered]@{
                'FolderName'=$Folder.FullName
                'AD Group or User'=$Access.IdentityReference
                'Permissions'=$Access.FileSystemRights.ToString()
                'Inherited'=$Access.IsInherited
            }
            $Report += New-Object -TypeName PSObject -Property $Properties
        }
}
# 导出前确保目标目录存在
if (-not (Test-Path "C:\data")) {
    New-Item -ItemType Directory -Path "C:\data" | Out-Null
}
$Report | Export-Csv -path "C:\data\FolderPermissions.csv" -NoTypeInformation -Encoding UTF8

补充说明

  • 新增的-NoTypeInformation参数可以去掉CSV首行多余的类型说明内容,-Encoding UTF8可以避免中文用户/组名乱码
  • 如果需要导出权限的原始数值形式,可将Permissions行替换为'Permissions'=[int]$Access.FileSystemRights
  • 如果需要拆分显示每个独立权限项,可将Permissions行替换为'Permissions'=($Access.FileSystemRights -split ', ' -join ', ')

内容的提问来源于stack exchange,提问作者testerwendy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 12:54:00