title: Powershell: export-csv, exclude certain data from tables
body: <p>i created a very small script to get certain information of SQL Server databases, this information will be passed on to another script. </p>
  
  <p>It bassicaly gets the name, and collation of the existings databases on the server, and writes the value's to a CSV file. The code is working, though I want to exclude the system databases from the file. Can anyone help me out achieving this, i am fairly new to Powershell, so please bear with me.</p>
  
  <p>Code:</p>
  
  <pre><code>  param (
  [parameter(mandatory=$true)] [string] $servername
  )
  
  [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
  $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $servername
  $dbs=$s.databases
  $dbs | select name, collation | export-csv C:\tmp\dbs.csv
  </code></pre>
  
  <p>CSV Output:</p>
  
  <pre><code>DB1,"SQL_Latin1_General_CP1_CI_AS"
  DB2,"SQL_Latin1_General_CP1_CI_AS"
  DB3,"SQL_Latin1_General_CP1_CI_AS"
  master,"Latin1_General_CI_AS"
  model,"Latin1_General_CI_AS"
  msdb,"Latin1_General_CI_AS"
  tempdb,"Latin1_General_CI_AS"
  </code></pre>
  
  <p>The ones i want excluded from the CSV file are the master, model, msdb and tempdb databases.</p>