top of page

PowerShell - Get Folder Permissions by UNC Recursive

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 14, 2022
  • 1 min read

Save as another Permission Walk.ps1 or named .ps1, This one is fast and informative including: Identity, AccessType, Permission, Inherited, Inheritance, BlockInheritance for parent and child output to csv

#############################


$TargetDirectory = "\\SERVER\SHARE" # UNC to Share


#############################


Function SubDirs {

Param (

$fDir

)

Return @(Get-ChildItem -Directory -Path $fDir | %{$_.FullName})

}


$OutFile = ($TargetDirectory.Substring(2)).Replace("\","_") + "_PermissionsWalk.csv"

If (Get-Item ".\$($OutFile)" -ErrorAction SilentlyContinue -WarningAction SilentlyContinue) {Remove-Item ".\$($OutFile)" -Confirm:$false -Force}

$RootFolder = Get-Item -Path $TargetDirectory

Write-Host $RootFolder.FullName

Get-Acl $RootFolder.FullName | %{

$BlockInheritance = $_.AreAccessRulesProtected

$_.Access | %{

New-Object -TypeName PSObject -Property @{

Path = $RootFolder.FullName

Identity = $_.IdentityReference

AccessType = $_.AccessControlType

Permission = $_.FileSystemRights

Inherited = $_.IsInherited

Inheritance = $_.InheritanceFlags

BlockInheritance = $BlockInheritance

} | Select Path,Identity,AccessType,Permission,Inherited,Inheritance,BlockInheritance | Export-Csv $OutFile -NoTypeInformation -Append

}

}

$DirArr = Get-ChildItem -Directory -Path $TargetDirectory | %{$_.FullName}

For ($i=0; $i -lt $DirArr.Count; $i++) {

$DirObj = Get-Item -Path $DirArr[$i]

Write-Host $DirObj.FullName

Get-Acl $DirObj.FullName | %{

$BlockInheritance = $_.AreAccessRulesProtected

$_.Access | %{

New-Object -TypeName PSObject -Property @{

Path = $DirArr[$i]

Identity = $_.IdentityReference

AccessType = $_.AccessControlType

Permission = $_.FileSystemRights

Inherited = $_.IsInherited

Inheritance = $_.InheritanceFlags

BlockInheritance = $BlockInheritance

} | Select Path,Identity,AccessType,Permission,Inherited,Inheritance,BlockInheritance | Export-Csv $OutFile -NoTypeInformation -Append

}

}

$DirArr += SubDirs $DirArr[$i]

}


 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page