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 closed" text and terminate. It must be something very simple, but I somehow can't find it through Google. Thank you very much for your help in advance!
Kind regards, Eric