Moccassin
Moccassin

Reputation: 169

How to separate columns in Powershell when exported to CSV

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 

}

Upvotes: 0

Views: 129

Answers (1)

Vivek Kumar Singh
Vivek Kumar Singh

Reputation: 3350

Try this

invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 60000 | export-csv $OutputFile -NoTypeInformation -append

Upvotes: 2

Related Questions