Getting query text from SSMS into a CSV with PowerShell

From SQL Server Wiki
Jump to navigation Jump to search
-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

What Links Here[edit]