Running netstat from within Powershell script -


i trying monitor f5 vpn client running on windows 7 laptop when established connection. designed simple powershell script utilize "netstat" command string variable available when connection established. planning on using microsoft's task scheduler trigger script every monitor connection / string variable.

if run following netstat command @ powershell window, returns information fine:

    ps c:\tmp> $c = netstat -ban | select-string "f5fltsrv"; $c.count     9 

but if run similar operator , variables in powershell script, keeps returning '0' (zero), fails.

here's actual powershell script using:

    $vpn = netstat -ban | select-string "f5fltsvr"      write-host "debug: " $vpn.count      if($vpn.count -gt 7) {     write-host "f5 vpn session enabled." -b green     exit     }     else {     write-host "f5 vpn session down!" -b red -f yellow     } 

when executed

    ps c:\tmp> .\f5_vpn_check.ps1     0     f5 vpn session down! 

can tell me have fault in script? powershell window running administrator priviledges , uac turned off.

could typo? instead of this:

$vpn = netstat -ban | select-string "f5fltsvr" 

you want this:

$vpn = netstat -ban | select-string "f5fltsrv" 

at least example used worked. note diff between svr , srv.


Comments