Rod
Rod

Reputation: 15455

PowerShell Invoke-Sqlcmd results to csv using CovertTo-Csv

Given:

How do I get the actual values of the column into csv?

Write-Output $sqlResult.Quantity | ConvertTo-Csv

Gives me:

#TYPE System.Int32

When it should be:

100,200

Upvotes: 0

Views: 230

Answers (1)

Darin
Darin

Reputation: 2368

The problem, which I honestly don't know why it is a problem, is that ConvertTo-CSV does not convert arrays to comma delimited strings.

So you have to use a different tool such as join, which converts each item in the array to a string and joins those strings with commas:

$sqlResult.Quantity -join ','

Upvotes: 2

Related Questions