windows server 2019 powershell for循环测试多个端口联通性

目录

一、Test-NetConnection

二、Powershell for循环测试多个端口


一、Test-NetConnection

        在windows server 2019中,为了测试端口联通性,使用telnet的方式台笨重,需要人工干预。

        请教朋友之后,知道了Test-NetConnection的命令,比如测试80端口命令如下:

Test-NetConnection 192.168.0.1 -Port 80

二、Powershell for循环测试多个端口

        为了进一步开发powershell监控脚本,使用了for循环监控多个端口,具体示例如下:

$test=22,80,443,445,1433,3306,3389
for($i=1;$i -le 7;$i++)
{

    Test-NetConnection 192.168.0.1 -Port $test[$i] | Select-Object tcptestsucceeded

}

你可能感兴趣的:(运维,windows)