PowerShell: test connection in as few characters as possible I need this down to as few characters as possible.  I would use Test-NetConnection but I need PSv2 compatability.  Any help would be appreciated.

$socket = new-object Net.Sockets.TcpClient
$socket.Connect("192.168.5.5",445)
$socket.Connected


As a note I have tried this but it doesn't work

(new-object Net.Sockets.TcpClient).Connect("192.168.5.5",445).Connected
PowerShell v2+, 63 bytes

You can use a different constructor to create the object and connect in one go.

(new-object Net.Sockets.TcpClient('192.168.5.5',445)).Connected


I've verified this works in v2 on my Windows 8.1 machine. That constructor is supported by .NET 2.0, so this should be v2 compatible.