Powershell check if Remote Machine Required Port is opened or Not

Need to make sure that PortQry is downloaded from the microsoft site and use below powershell script to check the same

http://www.microsoft.com/downloads/details.aspx?FamilyID=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en

$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
}

Leave a comment