PowerShell 2.0: One Cmdlet at a Time 6 Test-Connection
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Test-Connection cmdlet.
What can I do with it?
Send a ping to one or more computers
Examples:
Send a ping to Server01
Test-Connection -ComputerName Server01
If the result of a ping to Server01 is successful then copy a text file to a file share on that server
If (Test-Connection -computername Server01 -quiet) {Copy-Item C:\Document.txt “\\Server01\Fileshare”}
How could I have done this in PowerShell 1.0?
You could have used Get-WMIObject with the Win32_PingStatus class.
Get-WmiObject Win32_PingStatus -filter “Address=‘Server01’”
You could also have used the .NET System.Net.NetworkInformation.Ping class
$ping = New-Object System.Net.NetworkInformation.Ping $ping.send(‘Server01’)