Joe
Joe

Reputation: 69

Format SQL output in Powershell ISE

Using Invoke-SQLCMD and running a saved query, Is there a way to see the output as a table? Currently, All output is printed sequentially, such as Name newline state newline is_encrypted for each item returned from the query rather than a row-column table where name, state, is_encrypted, etc. are the column headers.

The end goal is to output all the results of the query into a text or excel file.

Upvotes: 0

Views: 159

Answers (1)

k7s5a
k7s5a

Reputation: 1377

Try this:

Invoke-Sqlcmd -query $sql | Export-Csv -Path c:\temp\excelfile.csv -NoTypeInformation

Upvotes: 2

Related Questions