Getting query text from SSMS into a CSV with PowerShell


 * http://www.sqlservercentral.com/articles/PowerShell/130717/

-ServerInstance ?servername?\?instance? -Database master -Query $XEquery | select event_name,timestamp,activity_id, event_sequence, @{label="sql_text";expression={$_.sql_text -replace "`n"," "}} | Export-Csv -Path .\outfile.csv -NoClobber -Delimiter "|" -NoTypeInformation -Force