gpt4 book ai didi

powershell - 没有 "quotes"和 header 的 Invoke-sqlcmd 输出

转载 作者:行者123 更新时间:2023-12-02 22:34:21 28 4
gpt4 key购买 nike

输出示例:

#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"

要求:

我想要一个没有前 2 行和引号的输出,我该怎么做?

对于标题,我尝试了选项 -h -1但输出仍然相同。甚至可以使用 Sqlcmd ?

当前代码:
Invoke-Sqlcmd -ServerInstance SERVER -h -1 -Query $QueryFmt | Export-CSV $AttachmentPath

最佳答案

此代码应该工作:

Invoke-Sqlcmd -ServerInstance "" -Database "" -Query "" | ConvertTo-Csv -NoTypeInformation -Delimiter "," | Select-Object -Skip 1 | % {$_ -replace '"', ""} | Out-File ("C:\test.csv") -Force -Encoding ascii
Invoke-Sqlcmd产生:
PersonalNr       
---
00001005
00001001
00001006
00001007
00001008

Export-Csv ,文件看起来像:
#TYPE System.Data.DataRow
"PersonalNr"
"00001005"
"00001001"
"00001006"
"00001007"
"00001008"

使用我上面提到的代码,我得到的文件如下所示:
00001005
00001001
00001006
00001007
00001008

关于powershell - 没有 "quotes"和 header 的 Invoke-sqlcmd 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43047946/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com