1

I have the script below that works just fine, but i need to use the pipe separator as a column separator, help :

$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 Answer 1

1

You need to use the parameter -s and then I would use quotes and put the pipe into those quotes i.e.

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

As Per Matt's comment :

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

Sign up to request clarification or add additional context in comments.

4 Comments

is there a way to use Invoke-Sqlcmd ?
msdn.microsoft.com/en-us/library/cc281720.aspx I doubt that this option is actually available using invoke-sqlcmd, you could try wrapping the pipe in quotes but as you have specified export-csv then I suspect that you will always get a comma delimited output.
Just because of that last comment i want to chime in here.@GabrielGonzales Is it the output created by Export-CSV that you want to control to column separator? Export-Csv $AttachmentPath6 -Delimiter "|"
@Matt I was just about to put that in :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.