Advertisement
Ubidibity

EnumerateACLs.ps1

Jan 29th, 2025 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.13 KB | Cybersecurity | 0 0
  1. # This will enumerate all the permissions for the current folder and write them into an output file based on the machine
  2. # name, date, time at the $destPath location.
  3.  
  4. # User tunable, set this to where you want the output to go if it's different than the current folder:
  5. $destPath="c:\users\jimbo\Documents\"
  6.  
  7. # Get hostname
  8. $hostname = $env:COMPUTERNAME
  9.  
  10. # Try to get the domain name, fallback to just hostname if domain can't be retrieved
  11. try {
  12.     $domain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name
  13.     $filenamePrefix = "$domain-$hostname"
  14. } catch {
  15.     $filenamePrefix = $hostname
  16. }
  17.  
  18. # Get current date and time
  19. $now = Get-Date
  20. $formattedDateTime = $now.ToString("yyMMdd-HHmm")
  21.  
  22. # Construct the filename
  23. $outputFileName = "$destPath$filenamePrefix-$formattedDateTime.csv"
  24.  
  25. Get-ChildItem | ForEach-Object {
  26.     $acl = Get-Acl $_.FullName
  27.     [PSCustomObject]@{
  28.         Path = $_.FullName
  29.         Owner = $acl.Owner
  30.         Access = ($acl.Access | ForEach-Object { "$($_.IdentityReference) - $($_.FileSystemRights)" }) -join "; "
  31.     }
  32. } | Export-Csv -Path $outputFileName -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement