Created
January 24, 2020 16:44
-
-
Save JohnLBevan/997dc43bc22e3579f54b77d1f64d1f7e to your computer and use it in GitHub Desktop.
Powershell Ping - Gives a bit more detail than Test-Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param([string]$ComputerName) | |
[System.Collections.Generic.IDictionary[[uint32],[string]]]$statusCodes = New-Object -TypeName 'System.Collections.Generic.Dictionary[[uint32],[string]]' | |
# list from https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmipicmp/win32-pingstatus | |
@' | |
Success (0) | |
Buffer Too Small (11001) | |
Destination Net Unreachable (11002) | |
Destination Host Unreachable (11003) | |
Destination Protocol Unreachable (11004) | |
Destination Port Unreachable (11005) | |
No Resources (11006) | |
Bad Option (11007) | |
Hardware Error (11008) | |
Packet Too Big (11009) | |
Request Timed Out (11010) | |
Bad Request (11011) | |
Bad Route (11012) | |
TimeToLive Expired Transit (11013) | |
TimeToLive Expired Reassembly (11014) | |
Parameter Problem (11015) | |
Source Quench (11016) | |
Option Too Big (11017) | |
Bad Destination (11018) | |
Negotiating IPSEC (11032) | |
General Failure (11050) | |
'@ -split '[\r\n]+' | ForEach-Object {if ($_ -match '^([^\(]+)\((\d+)\)\s*$') {$statusCodes.Add([uint32]$Matches[2], $Matches[1])}; } | |
$ping = Get-WmiObject -Class 'Win32_PingStatus' -Filter "Address='$ComputerName' and Timeout=5000" | |
$statusCodes[$ping.StatusCode] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment