# encoding: ascii
# api: powershell
# title: Test-Port.ps1
# description: Test-Port creates a TCP connection to specified port.
# version: 0.1
# author: BSonPosh
# license: CC0
# x-poshcode-id: 2392
# x-derived-from-id: 6442
# x-archived: 2016-08-19T05:15:23
# x-published: 2011-11-28T08:57:00
#
#
param ($ComputerName,$Port)

$sock = new-object System.Net.Sockets.Socket -ArgumentList $([System.Net.Sockets.AddressFamily]::InterNetwork),$([System.Net.Sockets.SocketType]::Stream),$([System.Net.Sockets.ProtocolType]::Tcp)

try {
    $sock.Connect($ComputerName,$Port)
    $sock.Connected
    $sock.Close()

}
catch {
    $false
}
