Quantcast
Channel: Virtual Machine Manager – General forum
Viewing all articles
Browse latest Browse all 2770

PowerShell to detect port availability on multiple servers

$
0
0

I've found the PowerShell script below to check whether a port on a server is open or not but how do I make it so that I can run this against a list of servers and a list of ports stored in txt files?  How can I search UPD and TCP lists? Foreach?

$Servername = Read-Host "Enter the Servername"
$PortNumber = Read-Host "Enter the Port Number"
$K = .\PortQry.exe -n $Servername -e $PortNumber -p TCP
$L = $K -Match "LIS?"
If($L -ne $null)
{
$res = $servername + " has " + $PortNumbe + "Opened"
Write-Host $res

}
Else
{
$res = $servername + " has " + $PortNumbe + "Closed"
Write-Host $res
} 



Viewing all articles
Browse latest Browse all 2770

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>