首页 > 解决方案 > 使用 Powershell 导出 NTFS 安全权限

问题描述

使用 Powershell,我如何获得 D: 驱动器中明确定义每个人访问权限的文件夹列表?

我已经安装了下面的模块,但不确定如何安排命令并将其导出到 .CSV 文件。

https://ntfssecurity.readthedocs.io/en/latest/ https://devblogs.microsoft.com/scripting/weekend-scripter-use-powershell-to-get-add-and-remove-ntfs-permissions/

标签: powershell

解决方案


这在某种程度上取决于您希望导出的外观。但是,以下示例是一个起点:

$StartPath = "C:\temp\08-28-19"

Get-ChildItem $StartPath | 
Get-NTFSAccess -Account Everyone | 
Select-Object FullName,Account,AccessRights,Type |  
Export-Csv c:\temp\PermExport.csv -NoTypeInformation

所以你/我们可能不得不处理这个Select-Object命令。请使用所需输出的示例更新问题,我们将对此进行更多讨论。

注意:如果路径可能超过 260 个字符,则会出现一些复杂情况。NTFSSecurity 模块包括Get-ChildItem2基于 AlphaFS .Net 库的命令。但是,在命名方面存在一些错误,这些错误记录在我简要报告的这个GitHub 问题中。

但是,您可以使用带有 good-old 的替代语法Get-ChildItem来列出长路径。这可能看起来像这样:

对于 UNC:

Get-ChildItem '\\?\UNC\<ServerName>\Share\RemainingPath' -Recurse |
...

对于本地驱动器:

Get-ChildItem '\\?\c:\temp' -Recurse |
...

推荐阅读