Created
December 9, 2021 10:11
-
-
Save nichollsc81/502dc183224fdd9d39a897f72ccafda9 to your computer and use it in GitHub Desktop.
Test if port is open or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-Port | |
{ | |
param | |
( | |
$Address, | |
$Port | |
) | |
$tcpClient = New-Object Net.Sockets.TcpClient | |
try | |
{ | |
$tcpClient.Connect("$Address", $Port) | |
$true | |
} | |
catch | |
{ | |
$false | |
} | |
finally | |
{ | |
$tcpClient.Dispose() | |
} | |
} | |
# Test-Port -Address localhost -Port 22 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment