ICMP.psm1
function Test-ICMP { [cmdletBinding()] param( [parameter(Mandatory=$true)] [string]$ComputerName, #[ValidateRange(0, 1000)] [uint32]$Count=4, [ValidateRange(1, 10000)] [uint32]$Timeout=500, [ValidateRange(1, 128)] [byte]$TTL=128, [ValidateRange(20,980)] [uint16]$Length = 32, [Switch]$Quiet ) $result = $false if ($Count -eq 0) { $Count = 2GB } $ps = New-Object System.Net.NetworkInformation.Ping $data = "a quick brown fox jumped over the lazy dog" $buffer = [System.Text.Encoding]::ASCII.GetBytes($data) $po = New-Object System.Net.NetworkInformation.PingOptions $po.DontFragment = $true $po.Ttl = $TTL for ($i = 1; $i -le $Count; $i++) { $reply = $ps.Send($ComputerName, $Timeout, $buffer, $po) if (-not $Quiet) { Write-Output ([PSCustomObject]@{ PSTypeName = 'My.ICMPResult' Number = $i Address = $reply.Address Status = $reply.Status Time = $reply.RoundtripTime TTL = $reply.Options.Ttl Data = $reply.Buffer.Length }) } else { if ($reply.Status -eq 'Success') { $s = $true } else { $s = $false } $result = $result -or $s } } if ($Quiet) { return $result } } #$TypeData = @{ # TypeName = 'My.ICMPResult' # DefaultDisplayPropertySet = 'Status','Time','TTL' #} #Update-TypeData @TypeData #Update-FormatData -AppendPath .\Test-ICMP.format.ps1xml |