Ad Widget

Collapse

User Parameter and Powershell - variable problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PhilSynek
    Junior Member
    • May 2012
    • 13

    #1

    User Parameter and Powershell - variable problem

    Hi everyone,

    I want to monitor the connections on a windows machine. I want to see, per port, how many connections are established, waiting and listening. For this purpose I created a User Parameter:

    Code:
    UserParameter=custom.connections[*], C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command (netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count
    When I run this command in Powershell it works, of course. But when I do a zabbix_get from my server it returns this:

    Code:
    zabbix_get -s 10.1.1.1 -k custom.connections["10050","time_wait"]
    'Measure-Object).count' is not recognized as an internal or external command,
    operable program or batch file.
    The agents log in debug mode tells me this:

    Code:
    169580:20150527:123146.614 Requested [custom.connections[10050,time_wait]]
    169580:20150527:123146.692 Run remote command [ C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command (netstat -nao| findstr /i "time_wait" | findstr "10050" | Measure-Object).count] Result [110] ['Measure-Object).cou]...
    169580:20150527:123146.692 Sending back ['Measure-Object).count' is not recognized as an internal or external command,
    operable program or batch file.]
    Unfortunately I don't see, where the problem is.

    Can someone help me?

    Thanks!
    Phil
  • PhilSynek
    Junior Member
    • May 2012
    • 13

    #2
    Anyone got an idea?

    Comment

    • Avinasha
      Member
      • Jan 2018
      • 40

      #3
      I'm at a similar spot. has got the same issue. Any leads?

      Comment

      • PhilSynek
        Junior Member
        • May 2012
        • 13

        #4
        Originally posted by Avinasha
        I'm at a similar spot. has got the same issue. Any leads?
        Sorry, I was never able to resolve this issue.

        Comment

        • PhilSynek
          Junior Member
          • May 2012
          • 13

          #5
          Originally posted by splitek
          Option 1:
          Put all command in .ps1 file. Run this file form CMD not from Powershell - is still working?
          In userparameter add
          C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -ExecutionPolicy Bypass -file C:\path_to_script\some.ps1

          Option 2:
          Try like that:
          powershell.exe -command "(netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count"

          Always test your commands from CMD not from powershell, because agent is running commands outside powershell.

          ---
          My test:

          Code:
          D:\>powershell.exe -command (netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count
          'Measure-Object).count' is not recognized as an internal or external command,
          operable program or batch file.
          
          D:\>powershell.exe -command "(netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count"
          FINDSTR: Bad command line
          FINDSTR: Bad command line
          0
          Thank you splitek,

          unfortunately I am not able to test this, since I am not working in a company anymore that is using zabbix.

          Cheers,
          Phil

          Comment

          • Sylvia99
            Junior Member
            • Oct 2019
            • 1

            #6
            Originally posted by splitek
            Option 1:
            Put all command in .ps1 file. Run this file form CMD not from Powershell - is still working?
            In userparameter add
            C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -ExecutionPolicy Bypass -file C:\path_to_script\some.ps1

            Option 2:
            Try like that:
            powershell.exe -command "(netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count"

            Always test your commands from CMD not from powershell, because agent is running commands outside powershell.

            ---
            My test:

            Code:
            D:\>powershell.exe -command (netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count
            'Measure-Object).count' is not recognized as an internal or external command,
            operable program or batch file.
            
            D:\>powershell.exe -command "(netstat -nao| findstr /i "$2" | findstr "$1" | Measure-Object).count"
            FINDSTR: Bad command line
            FINDSTR: Bad command line
            0
            Thank you splitek

            Your article is so useful for us,thanks for sharing. Good stuff!

            Comment

            Working...