Functions/Networking/Test-Port.ps1
function Test-Port { [cmdletbinding()] param ( # IP to Test [parameter(Mandatory=$false)] [string] $IPAddress = '127.0.0.1', # Port number to Test [parameter(Mandatory=$false)] [string] $Port = '80' ) begin { $tcp = New-Object Net.Sockets.TcpClient } process { try {$tcp.Connect($IPAddress, $Port)} catch {} $open = if ($tcp.Connected) {$true; $C = $tcp.Close()} else {$false} [pscustomobject]([ordered]@{ IPAddress = $IPAddress Port = $Port Test = $open }) } } |