问题
Output example:
#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"
Requirements:
I want a output without the 2 first lines and without the quote symbols, how can i do that?
For the headers I tried the options -h -1
but the output is still the same. Is it even possible with Sqlcmd
?
Current Code:
Invoke-Sqlcmd -ServerInstance SERVER -h -1 -Query $QueryFmt | Export-CSV $AttachmentPath
回答1:
This code should work:
Invoke-Sqlcmd -ServerInstance "" -Database "" -Query "" | ConvertTo-Csv -NoTypeInformation -Delimiter "," | Select-Object -Skip 1 | % {$_ -replace '"', ""} | Out-File ("C:\test.csv") -Force -Encoding ascii
Invoke-Sqlcmd
produces:
PersonalNr
---
00001005
00001001
00001006
00001007
00001008
With Export-Csv
, the file looks like:
#TYPE System.Data.DataRow
"PersonalNr"
"00001005"
"00001001"
"00001006"
"00001007"
"00001008"
Using my above mentioned code, I get the file looking like this:
00001005
00001001
00001006
00001007
00001008
回答2:
Try this:
## You data for export to csv
$csv = Invoke-Sqlcmd -ServerInstance SERVER -Query $QueryFmt
#
##Will remove type information and will remove header
$csv | Export-CSV -NoTypeInformation | select -Skip 1 | Set-Content $AttachmentPath
#
回答3:
Try this,
$query_result | Format-Table -AutoSize -Wrap -HideTableHeaders
来源:https://stackoverflow.com/questions/43047946/invoke-sqlcmd-output-without-quotes-and-headers