首页 > 解决方案 > 导出更大输出的最佳格式是什么?

问题描述

我有一个大文件服务器,有一个大文件和文件夹树,我需要导出 NTFS 权限。我使用了以下脚本:

$FolderPath = Get-ChildItem -Path C:\FS -Filter * -Recurse -Force 

ForEach ($Folder in $FolderPath) {
  $Acl = Get-Acl -Path $Folder.FullName
  ForEach ($Access in $Acl.Access) {
    $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
    New-Object -TypeName PSObject -Property $Properties
  }
}

什么样的格式建议我从脚本中得到结果,我认为 CSV 是一种非常好的格式,但我不知道是否是正确的文件格式。

标签: databasepowershellfileserver

解决方案


您可以写入 CSV 格式,以后在 excel 或其他地方处理它们会更容易。

$FolderPath = Get-ChildItem -Path C:\FS -Filter * -Recurse -Force 

$collection = @() #Define collection
ForEach ($Folder in $FolderPath) {
  $Acl = Get-Acl -Path $Folder.FullName
  ForEach ($Access in $Acl.Access) {
    $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
    $collection += New-Object -TypeName PSObject -Property $Properties
  }
}
$collection | Export-Csv -LiteralPath C:\ACLInformation.csv -NoTypeInformation -Encoding UTF8

推荐阅读