Export-CSV如何使用列分隔符

时间:2014-09-18 15:03:00

标签: powershell csv pipe invoke

我有下面的脚本工作正常,但我需要使用管道分隔符作为列分隔符,帮助:

$enddate = (Get-Date).tostring("yyyyMMdd")
$AttachmentPath6 = 'D:\PerfTeam_Queries\' + $enddate + '_Interfaces.csv'
$QueryFmt6= "SELECT NodeID,InterfaceID,InterfaceName,InterfaceType,InterfaceTypeDescription,InterfaceSpeed,InterfaceMTU,InBandwidth,OutBandwidth,FullName FROM Interfaces; "
Invoke-Sqlcmd -ServerInstance localhost -Database NetPerfMon -Query $QueryFmt6 | Export-CSV $AttachmentPath6

1 个答案:

答案 0 :(得分:1)

你需要使用参数-s然后我会使用引号并将管道放入那些引号,即

sqlcmd -S localhost -d NetPerfMon -Q $ QueryFmt6 -s“|” -o $ AttachmentPath6

根据Per Matt的评论:

Invoke-Sqlcmd -ServerInstance localhost -Database NetPerfMon -Query $ QueryFmt6 | Export-CSV -Delimiter'|' $ AttachmentPath6