Tuesday, 6 August 2013

Powershell one liner to check that a server is listening on a particular port

A lot of times I find myself trying to RDP to a box following a reboot only to be denied because although the box is pinging, not all services are up, so I can't connect to the box. This handy one liner helps by displaying errors until the connection on the port can be made.
$s = New-Object system.net.sockets.tcpclient; while (-not ($s.Connected)){$s.Connect("",3389)}
Needless to say that if you change the port you can test any other service.

No comments:

Post a Comment