title: Powershell and writing to csv an array of objects
body: <p>Below I have a script that loops through a list of servers, remotes into them, grabs some data and writes it to csv file:</p>
  
  <pre><code>$results = @()
  $serverList = Get-Content C:\Test\Servers.txt
  foreach ($server in $serverList) {
  
  if((Test-Connection -Cn $server -BufferSize 16 -Count 1 -ea 0 -quiet))
  {
  
      $myobj = Get-ChildItem ...
     Write-Host $myobj.Name
  
       $result =  New-object PSObject
       $result | Add-member -type Noteproperty -Name ServerName $server.ToString()
       $result | Add-member -type Noteproperty -Name MyValue -Value $myobj.Name
  
       Write-Host $result
  
       $results += $result
     }
  }
  $results | export-csv -Path c:\Test\Output.csv 
  </code></pre>
  
  <p>The above writes 2 columns to <code>csv</code> file, first column is the server name displayed correctly, but second column get the value of <code>System.Object[]</code> even though above  <code>Write-Host $myobj.Name</code> outputs the correct value. How can i fix my code to display the correct value in a csv file?</p>