[CmdletBinding()] param( [string]$Target = 'example.com', [ValidateRange(1, 30)] [int]$MaxHops = 15, [int]$TimeoutMs = 1000 ) $ErrorActionPreference = 'Stop' Write-Host ("Tracing route to {0}, max hops {1}" -f $Target, $MaxHops) $output = & tracert.exe -d -h $MaxHops -w $TimeoutMs $Target 2>&1 $output | ForEach-Object { Write-Host $_ } $hops = @($output | Where-Object { $_ -match '^\s*\d+\s' }) if ($hops.Count -eq 0) { Write-Host 'ERROR: no route information received' exit 2 } Write-Host ("Hops: {0}" -f $hops.Count) exit 0