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
+1 received by user: 32


#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"

Create new topic

This is a filtered page: currently showing replies marked as answers. Click here to see full discussion.

Inphinity
2780 posts

Uber Geek
+1 received by user: 1184


  #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

 

 




Inphinity
2780 posts

Uber Geek
+1 received by user: 1184


  #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
}


Create new topic








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.