【问题标题】:PowerShell - to check multiple Port StatusPowerShell - 检查多个端口状态
【发布时间】:2023-01-04 21:58:23
【问题描述】:

我试图使用如下所示的 powershell 检查端口是否打开。

我的问题是:我想检查多个端口,例如 389,53,135。我们该怎么做?

这是我的脚本:

$Ipaddress= "xx.xx.xx.xx"
$Port= "389"

$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
    if($t.Connected)
    {
        "Port $Port is operational"
    }
    else
    {
        "Port $Port is closed, You may need to contact your IT team to open it. "
    }

我想要的输出:

Port 389 is operational;Port 53 is operational;Port 135 is operational

【问题讨论】:

    标签: powershell


    【解决方案1】:

    使用 PowerShells Test-NetConnection 并将其放入循环访问端口数组的循环中。

    有关语法和用法,请参阅https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=windowsserver2022-ps

    【讨论】:

      猜你喜欢
      • 2010-09-12
      • 2013-04-17
      • 2013-10-17
      • 2010-11-13
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多