How to Get NTFS Permissions Report with PowerShell

This article provides step-by-step guidance on generating NTFS permissions reports for folders and files using PowerShell.

In this Guide:

Managing NTFS permissions is crucial for keeping your files and folders secure in Windows environments. With Windows PowerShell, you can effortlessly retrieve, report and manage these permissions, giving administrators the ability to monitor access and ensure everything stays compliant.

Why Manage NTFS Permissions?

  • Data Security: Safeguard sensitive files by limiting access to only those who are authorized.

  • Compliance: Keep an audit trail to satisfy regulatory requirements.

  • Operational Efficiency: Stop unauthorized access in its tracks and reduce the risk of data breaches. 

Understanding NTFS permissions is key to maintaining a secure and compliant IT environment. Permissions can either be explicit (set directly on a folder or file) or inherited (passed down from a parent folder).

Steps to Get NTFS Permissions Report Using PowerShell

1. Open Windows PowerShell

  • Start by pressing Win + X and choosing Windows PowerShell (Admin) to launch it with the necessary elevated permissions.

2. Use the Get-Acl Command

The Get-Acl cmdlet is your go-to for fetching NTFS permissions for a specific folder.

Example Command:

Get-Acl -Path "C:\FolderPath"

3. Export Permissions to a Report

To create a comprehensive report of permissions and save it as a file, you can use the following script:

$Path = "C:\FolderPath" $Report = "C:\NTFS_Permissions_Report.csv" (Get-ChildItem -Path $Path -Recurse | ForEach-Object { $Acl = Get-Acl $_.FullName $Acl.Access | Select-Object @{Name="File";Expression={$_.FileSystemRights}}, @{Name="User";Expression={$_.IdentityReference}}, @{Name="Access Control Type";Expression={$_.AccessControlType}} }) | Export-Csv -Path $Report -NoTypeInformation

This script:

  • Scan the specified folder and all its subfolders.
  • Extract file permissions, including rights, users, and access types.
  • Export the gathered data into a CSV file for easy review.

4. Validate the Report

Once you've generated the CSV file at the designated location, open it up to check the NTFS permissions. Look for any inconsistencies or permissions that might need tweaking.

5. Automate the Process

If you want to make this reporting a regular thing, save the script as a .ps1 file and set it up in Task Scheduler:

  • Open Task Scheduler and create a new task.
  • Set your triggers (like daily or weekly). -
  • Under Actions, add the script with:
    • powershell.exe -File "C:\PathToScript.ps1"

Advanced Use Cases

Filtering by Specific Users or Groups

If you want to check permissions for a particular user or group, you can do it like this:

Get-Acl -Path "C:\FolderPath" | Select-String -Pattern "SpecificUserName" Check for Inherited Permissions

Check for Inherited Permissions

To tell apart explicit permissions from inherited ones, use this command:

(Get-Acl -Path "C:\FolderPath").Access | Select-Object IdentityReference, FileSystemRights, IsInherited

Managing NTFS Permissions

To change permissions, you can use the Set-Acl cmdlet like this:

$Acl = Get-Acl "C:\FolderPath" $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("UserName", "FullControl", "Allow") $Acl.SetAccessRule($AccessRule) Set-Acl -Path "C:\FolderPath" -AclObject $Acl

Best Practices

  • Make it a habit to regularly check NTFS permissions so you can spot any inactive or compromised accounts.
  • Don’t forget to enable and set up auditing policies to keep track of all successful and failed logon attempts.
  • Consider using PowerShell scripts to automate the reporting of permissions, especially in larger environments.
  • Set up alerts for any unusual activity patterns to boost your security measures.
  • Make it a point to archive old log data from time to time. This helps keep your system running smoothly while still holding onto important records

Common Troubleshooting Tips

  • Execution Policy: If you run into execution restrictions, you can adjust the policy like this:

    • Set-ExecutionPolicy RemoteSigned
  • Error Handling: It’s a good idea to add error handling in your scripts to log any issues that come up:

    • try { # Script Code } catch { Write-Output "Error: $($_.Exception.Message)" }

  • Invalid Paths: If Get-Acl isn’t able to retrieve permissions, double-check the folder path.

Managing NTFS permissions with PowerShell is a great way to gain flexibility and efficiency, especially in larger environments. By using tools like Get-Acl, exporting reports, and automating tasks, administrators can ensure data security, compliance, and smoother operations. Regularly reviewing permissions and following best practices is key to maintaining a secure and compliant infrastructure.

Related Article


Frequently asked questions: