Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


Oriphix

523 posts

Ultimate Geek


#208376 9-Feb-2017 10:53

Hi Guys,
Need help with the Powershell command to output the results in a csv file.
The file gets created but the contents is blank or shows something which isn't the results.

Using Powershell ISE I can see the command is executing and giving the results but its not writing to the file. I'm sure its something simple that I am missing, just can't spot it.



$servers = "geekzone.co.nz","trademe.co.nz"

foreach ( $server in $servers )
{

Write-Host "Starting Ping for $server 'n" -ForegroundColor Yellow
test-Connection -ComputerName $server -Count 3
Write-Host "Completed `n" -ForegroundColor Yellow

}

$DesktopPath = [Environment]::GetFolderPath("Desktop") |
Export-Csv -Path "$DesktopPath\Ping.csv" -Append



Also tried to change from Export to Out-File but no dice (however the export and out-file should will give me the file so I think its something else I am missing.

Out-File -filepath "$DesktopPath\Ping.txt"

Filter this topic showing only the reply marked as answer Create new topic
Regs
4066 posts

Uber Geek

Trusted
Snowflake

  #1717590 9-Feb-2017 11:48
Send private message

Looks like you're not piping your output to the file . Either pipe each line to file, or pipe to variable and then pipe variable to file.

See some exampeles here:

https://msdn.microsoft.com/en-us/powershell/reference/4.0/microsoft.powershell.utility/out-file


(sorry about short answer, typing from phone in dark in conference session)






Inphinity
2780 posts

Uber Geek


  #1717592 9-Feb-2017 11:49
Send private message

At no point are you passing the output of your test-connection requests to any output - you're only piping the output of 

 

[Environment]::GetFolderPath("Desktop")

 

to the export-csv cmdlet

 

Try this:

 

 

 

$servers = "geekzone.co.nz","trademe.co.nz"

 

$outFile = "$([Environment]::GetFolderPath('Desktop'))\Ping.csv"

 

foreach ( $server in $servers )
{

 

Write-Output "Starting Ping for $server" | Out-File $outFile -Append
test-Connection -ComputerName $server -Count 3 | Out-File $outFile -Append
Write-Output "Completed"| Out-File $outFile -Append

 

}

 

 

 

Note that this won't display the output in the console, only in ping.csv on your desktop

 

 


Oriphix

523 posts

Ultimate Geek


  #1717598 9-Feb-2017 12:09

Thanks for the prompt reply guys.

@Inphinity that works great.

Do you know how I can format the excel so that each column goes into a separate cell rather then in the first one?

I found this article which says you can use

GPS winword,Excel,Outlook | Export-Csv c:\fso\procoff.csv –NoTypeInformation

However the export-csv bit you have removed and added it in one line. Is there a way to add that in the script?

https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/23/use-powershell-to-work-with-csv-formatted-text/





Inphinity
2780 posts

Uber Geek


  #1717645 9-Feb-2017 13:12
Send private message

You may need to delete the ping.csv file first

 

 

 

$servers = "geekzone.co.nz","trademe.co.nz"

 

$outFile = "$([Environment]::GetFolderPath('Desktop'))\Ping.csv"

 

foreach ( $server in $servers )

 

{

 

test-Connection -ComputerName $server -Count 3 | Export-Csv $outFile -Append
}


Oriphix

523 posts

Ultimate Geek


  #1717739 9-Feb-2017 15:14

Thanks for your help :) That works great now.

Filter this topic showing only the reply marked as answer Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.