title: Get individual folder permissions Powershell
body: <p>I have been asked to write a script which will take in a destination and then output the folders and subfolders with their respective permissions.</p>
  
  <p>I have got what I thought was a working script but have been told that they want the actual permission types. Can this actually be done using <code>Get-ACL</code>? Could anyone point me in the right direction for this I have no idea where to start with this and don't have all that much experience with using <code>Powershell</code></p>
  
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  
  $info = ""
  $OutputString = ""
  $step = 0
  $File = "C:\Gower\FolderPermissions.txt"
  
  function DisplayForm{
  $OutputString = ""
  
  #Some GUI Code here taken out for readability
  
  if ($result -eq [System.Windows.Forms.DialogResult]::OK)
  {
  
      $baseFolder = $textBox.Text
      $folderTest = Test-Path $baseFolder
      if($folderTest -eq "True"){
          "$baseFolder `r`n" | Out-File $File -Append
          Extract-Permissions($baseFolder)
          "`r`n`r`n" | Out-File $File -Append
          #OutputList
          $info = "SAVED TO $File"
          "Process complete `r`nFile Located at: $file"
          DisplayForm
      }else{
          $info = "$baseFolder not found"
          DisplayForm
      }
  }
  }
  
  function outputList{
      $OutputString
  }
  
  
  
  function Extract-Permissions($baseFolder) {
      $folders = Get-ChildItem $baseFolder | Where-Object { $_.PSisContainer }
      $baseACL = (Get-Acl $baseFolder).Access | Select-Object -ExpandProperty IdentityReference 
  
  "$baseFolder : $baseACL" | Out-File $File -Append
  
  if($folders.Count -ne 0){
      foreach($folder in $folders) {
          $folderACL = (Get-Acl $folder.FullName).Access | Select-Object -ExpandProperty IdentityReference
          $childFolders = Get-ChildItem $folder.FullName | Where-Object { $_.PSisContainer }
  
          "$($folder.FullName) : $folderACL" | Out-File $File -Append
  
          if($childFolders.Count -gt 0){
              foreach($childFolder in $childFolders) {
                  $childACL = (Get-Acl $childFolder.FullName).Access | Select-Object -ExpandProperty IdentityReference
                  if(Compare-Object $childACL $folderACL) {
                      Extract-Permissions $childFolder.FullName
                  } else {
                      "$($childFolder.FullName) : $childACL" | Out-File $File -Append
                  }
              }
          }
      }
  }
  }
  
  DisplayForm
  </code></pre>
  
  <p>This code will give me a list that then looks something like this:</p>
  
  <pre><code>C:\temp : BUILTIN\Administrators BUILTIN\Administrators NT AUTHORITY\SYSTEM NT AUTHORITY\SYSTEM BUILTIN\Users NT AUTHORITY\Authenticated Users NT AUTHORITY\Authenticated Users
  C:\temp\du : BUILTIN\Administrators BUILTIN\Administrators NT AUTHORITY\SYSTEM NT AUTHORITY\SYSTEM BUILTIN\Users NT AUTHORITY\Authenticated Users NT AUTHORITY\Authenticated Users
  C:\temp\Gower : BUILTIN\Administrators BUILTIN\Administrators NT AUTHORITY\SYSTEM NT AUTHORITY\SYSTEM BUILTIN\Users NT AUTHORITY\Authenticated Users NT AUTHORITY\Authenticated Users
  C:\temp\penout : BUILTIN\Administrators BUILTIN\Administrators NT AUTHORITY\SYSTEM NT AUTHORITY\SYSTEM BUILTIN\Users NT AUTHORITY\Authenticated Users NT AUTHORITY\Authenticated Users
  C:\temp\Projects : NT AUTHORITY\SYSTEM DOMAIN\Domain Users DOMAIN\TestAdmin
  C:\temp\Projects\A000 - Test0 : DOMAIN\Domain Users NT AUTHORITY\SYSTEM DOMAIN\TestAdmin
  C:\temp\Projects\A122 - Test12 : DOMAIN\Domain Users NT AUTHORITY\SYSTEM DOMAIN\TestAdmin
  C:\temp\Projects\A212 - TestA13 : DOMAIN\Domain Users NT AUTHORITY\SYSTEM DOMAIN\TestAdmin
  C:\temp\Projects\Template : DOMAIN\sam DOMAIN\Domain Users NT AUTHORITY\SYSTEM DOMAIN\TestAdmin
  </code></pre>