title: Get groups in folder permissions, and export the members of the groups to csv
body: <p>I am trying to Get the groups authority behind each folder of a drive and the username of each Member of the group, then export it to a CSV File.</p>
  
  <p>The problem is that the group has the directory name before the group e.g. <code>gescogroup/GR_blablabla</code>, so I remove <code>Gescogroup\</code> using <code>(Remove(0,12))</code>.</p>
  
  <p>As you see I first let the user chose the folder of the drive they want to analyze, then the code runs through the folders inside the drive and for each folder it gets the group, then with the name of the group (Removing the "Create owner, "Administrators", "Built "in etc) I should get the members.</p>
  
  <p>My code doesn't work, but I get no errors. Can you guys help me?</p>
  
  <pre><code> cls
      $result = [System.Windows.MessageBox]::Show("Select the path of the drive.`n"+"Once the Drive is selected, a excel file will be made with all the informations`n"+"of the selected Harddrive's directory premissions")
      if ($result = "OK")
      {
      Add-Type -AssemblyName System.Windows.Forms
      $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
      [void]$FolderBrowser.ShowDialog()
      $Selection = $FolderBrowser.SelectedPath
      }
      $result2 = [System.Windows.MessageBox]::Show("Pleas select where to save your file")
      if ($result2 = "OK")
      {
      Add-Type -AssemblyName System.Windows.Forms
      $FolderBrowser2 = New-Object System.Windows.Forms.FolderBrowserDialog
      [void]$FolderBrowser2.ShowDialog()
      $FolderBrowser2.Description = "Select where to save your file"
      $Selection2 = $FolderBrowser2.SelectedPath
      }
      $title = "ADPermissions.csv"
      $title2 = "ADPermissions2.csv"
      $ss =$Selection1 -replace '[\W]', ''
      $subtitle = "HardDrive"+ $ss
  
  
  
      $OutFile = ($Selection2+"\"+$subtitle+$title)
      Write-Host = $OutFile
  
  
  
         Remove-Item $OutFile
           $Header = "Folder Path,IdentityReference,names"
  
  
              $RootPath = $Selection
  
              $Folders = dir $RootPath  | where {$_.psiscontainer -eq $true}
        try {
         foreach ($Folder in $Folders){$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
                      Foreach ($ACL in $ACLs){
                      if($ACL.IdentityReference -notlike "Administrators" -and $ACL.IdentityReference -notlike "Creator Owner"-and $ACL.IdentityReference -notlike "BUILTIN\Administrators" -and $ACL.IdentityReference -notlike "NT AUTHORITY\SYSTEM" -and  $ACL.IdentityReference -notlike "System")
                          {
                         $strAcl = $ACL.IdentityReference
  
  
                                $strAcls = $ACL.IdentityReference.ToString()
                                $strUsers=@()
                               $strNames=$strAcls.Remove(0,12)
                               $A = Get-ADGroupMember -identity $strNames -Recursive | Get-ADUser -Property DisplayName | Select Name | Sort-Object Name
  
  
                                     foreach($strNames in $A)
                                     {
                                        $strUsers+=$A
  
                                     }
  
                             }
  
                               }
                               }
  
  
                                   $OutInfo =  $Folder.fullname + "," + $trAcl+$strUsers
                                  Add-Content -Value $OutInfo -Path $OutFile | sort-Object -Unique
  
                              }catch [System.IO.IOException] {
  
          }
  </code></pre>