[SOLVED] How to send real output without headers to file in PowerShell


I have a PowerShell script where I use Add-Content to send $output to log.txt. $output is generated as Test-Connection nrk.no -count 1 (nrk.no is a random website I trust will remain up most of the time). I now get a long string: \\NOTREALNAME\root\cimv2:Win32_PingStatus.Address="nrk.no",BufferSize=32,NoFragmentation=false,RecordRoute=0,ResolveAddressNames=false,SourceRoute="",SourceRouteType=0,Timeout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0 . How can I get the long one with hyphens and headers (see below), but remove the header part so that I log the user friendly part of the output but do not get header and then info over and over again in my log file?

"The long one with hyphens and headers":
enter image description here


Pipe the output to Format-Table -HideTableHeaders to get table formatted output without the header:

Test-Connection nrk.no |Format-Table -HideTableHeaders |Out-String -Stream |Add-Content log.txt

Answered By – Mathias R. Jessen

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *