title: Exporting System.Object[] to string in PowerShell
body: <p>I created a script that basically iterates through all lists in a site and its subsites and lists the permissions for each document or item.</p>
  
  <p>The script works, however, when being written to the CSV file the permissions (Member + Role) string gets written as <code>System.Object[]</code> instead of a proper string in the CSV output (e.g. <code>Member: user123 Role: Full Control</code>).</p>
  
  <p>Sample output:</p>
  
  <pre><code>"Common Hover Panel Actions", "https://#######.####.###.##", "https://######.######.#####.####", "System.Object[]", "                           Ministry for Finance", "Master Page Gallery", "12/22/2015 8:34:39 AM", "_catalogs/masterpage/Display Templates/Search/Item_CommonHoverPanel_Actions.js", "12/22/2015 8:34:39 AM", "6.2763671875"
  </code></pre>
  
  <p>The below is the script:</p>
  
  <pre><code>Add-PSSnapin Microsoft.SharePoint.PowerShell
  
  function Get-DocInventory([string]$siteUrl) {
      $site = New-Object Microsoft.SharePoint.SPSite $siteUrl
  
      $i = 0;
      foreach ($web in $site.AllWebs) {
  
          $count = $site.AllWebs.Count
          foreach ($list in $web.Lists) {
  
              if ($list.BaseType -ne “DocumentLibrary”)
              {
                 continue
              }
  
              foreach ($item in $list.Items) {
                  $data = @{
                      "Web Application" = $web.ToString()
                      "Site" = $site.Url
                      "Web" = $web.Url
                      "list" = $list.Title
                      "Item URL" = $item.Url
                      "Item Title" = $item["Title"]
                      "Item Created" = $item["Created"]
                      "Item Modified" = $item["Modified"]
                      "File Size" = $item.File.Length/1KB
                      "Permissions" = foreach($roleAssignment in $item.RoleAssignments)
                      {
                          $Permission = ""
  
                          foreach($roleDefinition in $roleAssignment.RoleDefinitionBindings)
                          {
                              $Permission = $(foreach($roleAssignment in $item.RoleAssignments){$roleAssignment}
                              {
                                  "Member: " +  $roleAssignment.Member.LoginName + " Role: " + $roleDefinition.Name + " "
                              } -join ',')
  
                              $Permission
                              Write-Progress -activity "Working" -status "Checked Sub-Site $i of $count" -percentComplete (($i / $count)/100)
                          }
                      }
                  }
                  New-Object PSObject -Property $data
              }
          }
          $web.Dispose();
      }
      $i++
      $site.Dispose()
  }
  &lt;# Get-DocInventory "https://#####.####.###.##/" | Out-GridView #&gt;
  Get-DocInventory "https://#####.####.###.##/" | Export-Csv -NoTypeInformation -Path C:\Users\livob002-lap\Desktop\Permissions-FinanceIntranet.csv
  </code></pre>
  
  <p>Is it possible to export the System.Object[] for the username as string in the CSV? The names appear as they should in the GridView.</p>