# NAME: AuditPerms2CSV.ps1
#
# AUTHOR: OldDog
# DATE : 11/12/2014
#
# COMMENT: Audit Folders/Shares and Export to CSV file
# This saves the results in a directory called C:\powershell\results
# if you don't have that directory it will create one.
# It also deletes any existing copy of Result.csv so if you want to save them rename them.
# ==============================================================================================
$path = $args[0]
if (! $args ) {
$path = Read-Host “Please enter the full path name you wish to check, like this: \\FileServer\share\user”
}
If (Test-path “C:\Powershell\Results”) {
If (Test-path “C:\Powershell\Results\Result.csv”) {
del “C:\Powershell\Results\Result.csv” }
}
Else {
New-Item -Path “C:\Powershell\Results” -ItemType directory
}
Add-Content “C:\Powershell\Results\Result.csv” “Folder Path:, Users/Groups:,Permissions:,Permissions Inherited:”
####Change the path to the folder or share you want NTFS perms on####
$dirToAudit = Get-ChildItem -Path $path -recurse | Where {$_.psIsContainer -eq $true}
foreach ($dir in $dirToAudit)
{
$colACL = Get-Acl -Path $dir.FullName
foreach ($acl in $colACL)
{
If ($acl.Access | ? inheritanceflags -eq ‘none’){
$In = $false } Else {$In = $True }
foreach ($accessRight in $acl.Access)
{
$DirName = $dir.FullName
$ar = $($AccessRight.FileSystemRights)
$id = $($AccessRight.IdentityReference)
Add-Content “C:\Powershell\Results\Result.csv” “$dirName ,$id,””$ar””,$In” #Note the “” to escape the ‘,’ in the permissions
}
$In = $null
}
}