← script library

Enhancing Security Compliance with PowerShell

Security & AuditingDecember 23, 2024

In today's post, I will share a useful script that focuses on auditing file and folder permissions to ensure security compliance within your organization. Regular audits of permissions are essential to protect sensitive data and maintain overall security posture. Below is a sample PowerShell script that scans a specified folder and generates a report of its permission settings:

powershell
# Specify the path of the folder to audit
$folderPath = "C:\Path\To\Your\Folder"
# Get the access control list for the folder
$acl = Get-Acl -Path $folderPath
# Create an array to store the permission audit results
$permissionAudit = @()
# Loop through the access rules and collect relevant information
foreach ($accessRule in $acl.Access) {
    $permissionDetails = [PSCustomObject]@{
        IdentityReference = $accessRule.IdentityReference
        AccessControlType = $accessRule.AccessControlType
        FileSystemRights  = $accessRule.FileSystemRights
        InheritanceType   = $accessRule.InheritanceType
    }
    $permissionAudit += $permissionDetails
}
# Export the results to a CSV file for further analysis
$permissionAudit | Export-Csv -Path "C:\Path\To\Your\PermissionAuditResults.csv" -NoTypeInformation
Write-Host "Permission audit completed. Results saved to PermissionAuditResults.csv."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.