Functions/Networking/Test-ComputerConnection.ps1
Function Test-ComputerConnection { [CmdletBinding()] param ( # HostName or IP [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelinebyPropertyName=$true)] [string] $ComputerName, # Timeout value [Parameter(Mandatory=$false)] [int] $Timeout = 25 ) Begin { [switch]$resolve = $true [int]$TTL = 128 [switch]$DontFragment = $false [int]$buffersize = 32 $options = new-object system.net.networkinformation.pingoptions $options.TTL = $TTL $options.DontFragment = $DontFragment $buffer=([system.text.encoding]::ASCII).getbytes("a"*$buffersize) } Process { $ping = new-object system.net.networkinformation.ping try {$reply = $ping.Send($ComputerName,$timeout,$buffer,$options) } catch {$ErrorMessage = $_.Exception.Message} $ONLINE = if ($reply.status -eq "Success") {$True} else {$False} [pscustomobject]([ordered]@{ ComputerName = $ComputerName Online = $ONLINE }) } } |