permissions.ps1 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. param (
  2. [string]$inputname = '',
  3. [string]$outputname = ''
  4. )
  5. Add-Type -AssemblyName System.Windows.Forms
  6. function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
  7. {
  8. Add-Type -AssemblyName Microsoft.VisualBasic
  9. return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText)
  10. }
  11. if ($inputname -eq $null -or $inputname -eq ""){
  12. $inputname = Read-InputBoxDialog -Message "Insert UNC path to Scan" -WindowTitle "Enter Path" -DefaultText "C:\Service\tools"
  13. }
  14. if ($inputname -eq $null -or $inputname -eq ""){
  15. exit
  16. }
  17. if ($outputname -eq $null -or $outputname -eq ""){
  18. $outputname = Read-InputBoxDialog -Message "Output CSV file" -WindowTitle "Enter Path" -DefaultText "C:\Service\dirs.csv"
  19. }
  20. if ($outputname -eq $null -or $outputname -eq ""){
  21. exit
  22. }
  23. function main {
  24. $FolderPath = Get-ChildItem -Directory -Path $inputname -Recurse -Force
  25. $Output = @()
  26. ForEach ($Folder in $FolderPath) {
  27. $Acl = Get-Acl -Path $Folder.FullName
  28. ForEach ($Access in $Acl.Access) {
  29. $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
  30. $Output += New-Object -TypeName PSObject -Property $Properties
  31. }
  32. }
  33. $Output | Export-Csv -Path $outputname
  34. $Output | Out-GridView -PassThru
  35. }
  36. main