How to Get NTFS Permissions Report with PowerShell

In this Guide:

Managing NTFS permissions is crucial for securing files and folders in Windows environments. Windows PowerShell provides an efficient way to retrieve, report, and manage NTFS permissions, enabling administrators to monitor access and ensure compliance.

Why Manage NTFS Permissions?

  • Data Security: Protect sensitive files by restricting access to authorized users only.

  • Compliance: Maintain an audit trail to meet regulatory requirements.

  • Operational Efficiency: Prevent unauthorized access and mitigate potential data breaches.

Understanding NTFS permissions is vital for maintaining a secure and compliant IT environment. Permissions can be explicit (set directly on a folder/file) or inherited (propagated from a parent folder).

Steps to Get NTFS Permissions Report Using PowerShell

1. Open Windows PowerShell

  • Press Win + X and select Windows PowerShell (Admin) to run it with elevated permissions.

2. Use the Get-Acl Command

The Get-Acl cmdlet retrieves NTFS permissions for a specified folder.

Example Command:

Get-Acl -Path "C:\FolderPath"

3. Export Permissions to a Report

To generate a detailed report of permissions and save it as a file, 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:

  • Scans the specified folder and its subfolders.

  • Extracts file permissions (rights, users, and access types).

  • Exports the data to a CSV file for easy review.

4. Validate the Report

Open the CSV file at the specified location to review the NTFS permissions. Check for inconsistencies or permissions that may need adjustment.

5. Automate the Process

For regular reporting, save the script in a .ps1 file and schedule it using Task Scheduler:

  • Open Task Scheduler and create a new task.

  • Set triggers (e.g., daily, weekly).

  • Add the script under Actions with:

    powershell.exe -File "C:\PathToScript.ps1"
 

Advanced Use Cases

Filtering by Specific Users or Groups

To check permissions for a specific user or group:

Get-Acl -Path "C:\FolderPath" | Select-String -Pattern "SpecificUserName"

Check for Inherited Permissions

To differentiate between explicit and inherited permissions:

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

Managing NTFS Permissions

To modify permissions, use the Set-Acl cmdlet:

$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

  • Regularly review NTFS permissions to identify inactive or compromised accounts.

  • Enable and configure auditing policies to log all successful and failed logon events.

  • Use PowerShell scripts to automate permissions reporting in large environments.

  • Set up alerts for unusual activity patterns to enhance security.

  • Archive old log data periodically to maintain system performance while retaining records.

Common Troubleshooting Tips

  • Execution Policy: If you encounter execution restrictions, adjust the policy with:

    Set-ExecutionPolicy RemoteSigned
  • Error Handling: Add error handling in scripts to log issues:

    try {
        # Script Code
    } catch {
        Write-Output "Error: $($_.Exception.Message)"
    }
  • Invalid Paths: Verify the folder path if Get-Acl fails to retrieve permissions.

 

Managing NTFS permissions with PowerShell offers flexibility and efficiency, especially in large-scale environments. By leveraging tools like Get-Acl, exporting reports, and automating tasks, administrators can ensure data security, compliance, and streamlined operations. Regularly review permissions and adopt best practices to maintain a secure and compliant infrastructure.

Related Article

 


Frequently asked questions: