Skip to content

Instantly share code, notes, and snippets.

@nichollsc81
Created December 9, 2021 10:11
Show Gist options
  • Save nichollsc81/502dc183224fdd9d39a897f72ccafda9 to your computer and use it in GitHub Desktop.
Save nichollsc81/502dc183224fdd9d39a897f72ccafda9 to your computer and use it in GitHub Desktop.
Test if port is open or not
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