Ad Widget

Collapse

PowerShell UserParameter not returning a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BrianS
    Junior Member
    • Apr 2013
    • 1

    #1

    PowerShell UserParameter not returning a value

    I am trying to write a PowerShell script that will return a value from a command line executable. My script is below:

    $text = vssadmin list writers
    for ($i=0; $i -lt $text.count; $i++) { if ($text[$i] -like "*Microsoft Exchange Writer*") { $outtext = $text[$i+3] } }
    $filteredText = $outtext -replace "^\s*State: \[(\d)].*$",'$1'
    $filteredText

    I have added the following line to the zabbix configuration:

    UserParameter=system.exchangevsswriter,%systemroot %\system32\WindowsPowerShell\v1.0\powershell.exe /nologo C:\Scripts\exchangevsswriter.ps1

    If I run the above command on the Zabbix client computer manually in the command line the script returns the correct value (a single digit). Also if I run a check on the zabbix server using telnet I get the following:

    [root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
    Trying 10.10.1.147...
    Connected to 10.10.1.147.
    Escape character is '^]'.
    system.exchangevsswriter
    ZBXD1Connection closed by foreign host.

    The value I am expecting to return is '1' which appears to be in the above output. However, the value in zabbix for that item never changes. The item is configured as a zabbix agent type with the key system.exchangevsswriter and I have tried both Text and Numeric(Unsigned). The strange thing is if I cause any error in the PowerShell script such that the script returns an error the error text is correctly shown for the item in zabbix. (Example below)

    [root@hozabbixdb01 ~]# telnet 10.10.1.147 10050
    Trying 10.10.1.147...
    Connected to 10.10.1.147.
    Escape character is '^]'.
    system.exchangevsswriter
    ZBXD[The string starting:
    At C:\Scripts\exchangevsswriter.ps1:4 char:1
    + <<<< "$filteredText
    is missing the terminator: ".
    At C:\Scripts\exchangevsswriter.ps1:4 char:15
    + "$filteredText <<<<
    + CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
    eption
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfStringConnection closed by foreign host.

    In the above example if I check the latest data for the item in zabbix I find the following text:

    The string starting:
    At C:\Scripts\exchangevsswriter.ps1:4 char:1
    + <<<< "$filteredText
    is missing the terminator: ".
    At C:\Scripts\exchangevsswriter.ps1:4 char:15
    + "$filteredText <<<<
    + CategoryInfo : ParserError: ($filteredText:String) [], ParseExc
    eption
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    If I remove the error and cause the script to return the correct value of '1' then the item never changes from the above text. It also never changes to unsupported. I just the the text "Zabbix agent item [system.exchangevsswriter] on host [hoexmb02] failed" in the zabbix log every time the item checks.

    Any ideas on what is causing this?
  • JDNight
    Junior Member
    • Nov 2006
    • 15

    #2
    PowerShell for UserParameter

    When I call a powershell script for a UserParameter I use the following command line:

    powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix\Service_Discovery.ps1"

    This should let you run a powershell script and return just the required value. In my scripts I output any return values with the Write-Host command.

    Comment

    • Tuor
      Junior Member
      • Feb 2015
      • 16

      #3
      Write-Output not Write-Host

      You have to use Write-Output not Write-Host.

      Comment

      Working...