0

Pretty new in PowerShell scripting, just wanted to ask how to achieve separated columns for my query below. Since currently all columns returned by the query is placed under one column when exported to csv file.

$QueryPath="\\fbrwnutap05\c$\DBA\Extended Events SQL DM\UAT\SQLDM_ExtendedEvent_UAT.sql"
$OutputFile= "\\FBRWNUTAP05\c$\DBA\SSRS\ExtEvent\QueryOutput_UAT.csv"

$ExecuteQuery= Get-Content -path $QueryPath | out-string

$OutputFile

FOREACH($server in GC "\\fbrwnutap05\c$\DBA\SSRS\ExtEvent\ServerList.txt")
{

invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 60000 | ft -autosize | out-string -width 4096 >> $OutputFile 

}

1 Answer 1

2

Try this

invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 60000 | export-csv $OutputFile -NoTypeInformation -append
Sign up to request clarification or add additional context in comments.

1 Comment

When exporting to a csv the | ft -autosize is superfluous.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.