ICMP.psm1

function Test-ICMP {
    [cmdletBinding()]
    param(
        [parameter(Mandatory=$true)]
        [string]$ComputerName,
        [ValidateRange(0, 1000)]
        [int]$Count=4,
        [ValidateRange(1, 10000)]
        [int]$Timeout=1000,
        [ValidateRange(1, 128)]
        [int]$TTL=128,
        [ValidateRange(20,980)]
        [int]$Length = 32
    )
    $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)
        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
        })
    }
}



#$TypeData = @{
# TypeName = 'My.ICMPResult'
# DefaultDisplayPropertySet = 'Status','Time','TTL'
#}
#Update-TypeData @TypeData
#Update-FormatData -AppendPath .\Test-ICMP.format.ps1xml