add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100
* Now you can export your data.
$Server = "serverName"
$DBName = "dataBase"
$QueryFmt= "SELECT * FROM Mytable"
$OutputFile = "output.csv"
Invoke-Sqlcmd -ServerInstance $Server -Database $DBName -Query $QueryFmt | Export-CSV $OutputFile