Power Shell script for open port check doesn't work properly
Modified on 2025-06-10 22:33:41 +0200
Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.
Important: We no longer maintain this article. The information might be out of date.
Hi,
I have a problem with PS script that is checking if port on remote host is open or not. I'm executing this script with Custom EXE/Script sensor and it is working but always giving the 1:ERROR value, below you will find the code :
try
{
$tcp=new-object System.Net.Sockets.TcpClient
$tcp.connect("10.10.10.10",445)
Write-Host "0:OK"
$tcp.close()
}
catch
{
Write-Host "1:ERROR"
}
Script is working fine with "Invoke command" from Powershell console and its giving the correct value.
Someone ?
Article Comments
Disclaimer:
The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.
Why not use the integrated port sensor?
Mar, 2016 - Permalink