I'm a bit new to Powershell scripting and I'm trying to create a simple loop with the Test-NetConnection
tool, but I don't know how to do this.
This is what I have:
param(
[string]$tcpserveraddress,
[string]$tcpport
)
if (Test-NetConnection -ComputerName $tcpserveraddress -Port $tcpport -InformationLevel Quiet -WarningAction SilentlyContinue) {"Port $tcpport is open" }
else {"Port $tcpport is closed"}
- If the tcpport is not open, I would like the script to loop and issue the text "Port $tcpport is closed" every 10 seconds, until it is open.
- When tcppport is open, it should display the "Port $tcpport is open" text and terminate.