Senior Systems Engineer
Senior Systems Engineer

Reputation: 1141

Using Powershell to export the NTFS security permissions

Using Powershell, how can I get the list of Folders in D: drive with Everyone access explicitly defined?

I've installed the module below, but not sure how to arrange the command and export it to .CSV file.

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

Upvotes: 0

Views: 980

Answers (1)

Steven
Steven

Reputation: 7087

It somewhat depends on what you want the export to look like. However, the below example is a starting point:

$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

So you/we may have to work on the Select-Object command. Please update the question with an example of desired output and we'll workshop this more.

Note: there are some complications if there's a risk of paths longer than 260 characters. The NTFSSecurity module includes commands like Get-ChildItem2 which are based on the AlphaFS .Net libraries. However, there are some bugs around naming, which are documented in this GitHub issue I briefly reported into.

However, you can use an alternate syntax with good-old Get-ChildItem to list long paths. That might look something like this:

For UNC's:

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

For Local Drives:

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

Upvotes: 1

Related Questions