Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Powershell脚本中运行netstat_Powershell_Powershell 4.0 - Fatal编程技术网

从Powershell脚本中运行netstat

从Powershell脚本中运行netstat,powershell,powershell-4.0,Powershell,Powershell 4.0,我正在尝试监视Windows 7笔记本电脑上运行的F5 VPN客户端,当其建立连接时。我设计了一个简单的Powershell脚本,它将利用“netstat”命令查找某个字符串变量,该变量仅在建立连接时可用。我计划使用Microsoft的Task Scheduler每隔一段时间触发一次脚本,以监视connection/string变量 如果我在Powershell窗口中运行以下netstat命令,它会很好地返回信息: PS C:\tmp> $c = netstat -ban | se

我正在尝试监视Windows 7笔记本电脑上运行的F5 VPN客户端,当其建立连接时。我设计了一个简单的Powershell脚本,它将利用“netstat”命令查找某个字符串变量,该变量仅在建立连接时可用。我计划使用Microsoft的Task Scheduler每隔一段时间触发一次脚本,以监视connection/string变量

如果我在Powershell窗口中运行以下netstat命令,它会很好地返回信息:

    PS C:\tmp> $c = netstat -ban | select-string "F5FltSrv"; $c.count
    9
但是,如果我在Powershell脚本中运行类似的运算符和变量,它会不断返回“0”(零),因此会失败

以下是我正在使用的实际Powershell脚本:

    $VPN = netstat -ban | select-string "F5FltSvr"

    Write-Host "DEBUG: " $VPN.count

    if($VPN.count -gt 7) {
    Write-Host "F5 VPN Session is enabled." -b Green
    exit
    }
    else {
    Write-Host "F5 VPN Session is down!" -b Red -f Yellow
    }
执行时

    PS C:\tmp> .\F5_VPN_Check.ps1
    0
    F5 VPN Session is down!

谁能告诉我剧本哪里有错吗?Powershell窗口正在以管理员权限运行,UAC已关闭。

可能是打字错误吗?与此相反:

$VPN = netstat -ban | select-string "F5FltSvr"
你想要这个:

$VPN = netstat -ban | select-string "F5FltSrv"

至少这是你用过的有效的例子。注意
Svr
Srv

之间的差异,你在哪个帐户下运行这个?哇。打字错误。这就是为什么最好有第二双眼睛。谢谢