← script library

Network Share Permission Reporter

Security & AuditingDecember 27, 2024

This PowerShell script is built to audit and report the permissions on network shares across a specified server. It is crucial for system administrators to regularly check permissions to maintain security and compliance within their organization. By utilizing this script in conjunction with ServerEngine, administrators can ensure that access to sensitive data is tightly controlled and that only authorized users have permissions to network resources.

powershell
param (
    [string]$serverName = "YourServerName"
)
# Getting the list of network shares
$shares = Get-WmiObject -Class Win32_Share -ComputerName $serverName
# Initialize an array to hold the permission details
$permissionsReport = @()
foreach ($share in $shares) {
    $shareName = $share.Name
    $securityDescriptor = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $serverName | Where-Object { $_.DeviceID -eq $share.Path }
    # Capture permission information
    $securityDescriptor | ForEach-Object {
        $permissions = @()
        $acl = Get-Acl $_.ProviderName
        foreach ($entry in $acl.Access) {
            $permissions += "$($entry.IdentityReference) - $($entry.FileSystemRights) - $($entry.AccessControlType)"
        }
        # Create an object to hold the share permission details
        $permissionsReport += [PSCustomObject]@{
            ShareName = $shareName
            Permissions = $permissions -join "; "
        }
    }
}
# Output the permissions report to a CSV file
$permissionsReport | Export-Csv -Path "C:\NetworkSharePermissions.csv" -NoTypeInformation
Write-Output "Network share permissions report has been created at C:\NetworkSharePermissions.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.