title: How to send output of Powershell script to CSV
body: <p>I have been given the following script to connect to an Azure subscription, get all the certificates and output some of the certificate properties.
  The script works fine, <br>
  <b>What I am trying to do is send the output into a CSV file</b> so I can sort by certificate expiry-date (for example) and manipulate the output into spreadsheet reports (for instance).</p>
  
  <p><H2>Powershell Script</H2></p>
  
  <pre><code>Set-AzureSubscription 'MySubscription'
  Select-AzureSubscription 'MySubscription'
  
  $enc = [system.Text.Encoding]::UTF8
  $azcerts = Get-AzureService | Get-AzureCertificate
  foreach ($azcert in $azcerts) {      
      $bytes = $enc.GetBytes($azcert.data) 
      $cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate -ArgumentList @(,$bytes)    
      $subjectstring = $cert.Subject
      $expirydate = $cert.GetExpirationDateString()
      $servicename = $azcert.ServiceName
      $thumprint = $azcert.Thumbprint
      $cnstring = $subjectstring -replace "(CN=)(.*?),.*",'$2'    
      Write-Output "$servicename, $cnstring, $expirydate, $thumprint"    }
  </code></pre>
  
  <h3> What I have tried... </h3>
  
  <p>When I try to replace the last line in the for-each loop with this I get a useless CSV file with only one column "#TYPE System.String"
  <br></p>
  
  <pre><code>"$servicename, $cnstring, $expirydate, $thumprint" | Export-Csv "outputfile.csv" -append -NoTypeInformation
  </code></pre>