top of page

PowerShell - Permission walk by UNC

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

Save the code as a .ps1, run it and enter the \\server\share to discover, outputs to the profile that runs its directory.


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


$TargetDirectory = Read-Host "Enter - \\server_name\share"


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


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

If (Get-Item ".\$($OutFile)") {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

}

}

Get-ChildItem -Directory -Path $TargetDirectory -Recurse -Force | %{

Write-Host $_.FullName

$FolderName = $_.FullName

Get-Acl $_.FullName | %{

$BlockInheritance = $_.AreAccessRulesProtected

$_.Access | %{

New-Object -TypeName PSObject -Property @{

Path = $FolderName

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

}

}

}



 
 
 

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