I am trying to write a PS script that will open a TCP port for an extended period of time. Below is my working script. It works fine. My issue is, if I set the: "start-Sleep" to like 3600 seconds is when I run into an issue.
The Script continues to sleep for the full 3600 seconds but after a random amount of time, could be 15 minutes, 30 minutes the server (or something on the server) shuts the port mid script and I can't telnet into the port (but script is still running).
I have disabled the Windows Firewall to eliminate this as the issue.
I am running this on Windows Server 2008 R2 SP1. Thoughts?
$Listener = [System.Net.Sockets.TcpListener]33335
write-host "Waiting for a connection on port $port..."
write-host "Port 33335 Open!"
start-Sleep -s 60
write-host "Port 33335 Closed!"