Ad Widget

Collapse

Powershell-ITEM via Zabbix-Agent

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • piti87
    Junior Member
    • Jun 2020
    • 23

    #1

    Powershell-ITEM via Zabbix-Agent

    Hello,

    I try to create a Item on den Zabbix-Server for the agent.
    I want to get the last update date (windows Updates).

    My Key is:
    system.run[PowerShell.exe -nologo -command "(Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)"]

    Now I got the error:
    In Zeile:1 Zeichen:45
    + (Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select- ...
    + ~
    Schlie?ende ")" fehlt in einem Ausdruck.
    In Zeile:1 Zeichen:115
    + ... Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)
    + ~
    Unerwartetes Token ")" in Ausdruck oder Anweisung.
    + CategoryInfo : ParserError: ( [], ParentContainsErrorRecordEx
    ception
    + FullyQualifiedErrorId : MissingEndParenthesisInExpression


    Executed in a powershell-shell as
    "Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date"
    it works.

    Any ideas?

    Thanks a lot!
  • Answer selected by piti87 at 05-07-2023, 17:04.
    dimir
    Zabbix developer
    • Apr 2011
    • 1080

    Perhaps it needs the escape symbol to be passed further then, try with triple backslashes:
    Code:
    system.run[PowerShell.exe -nologo -command \\\"(Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)\\\"]

    Comment


    • piti87
      piti87 commented
      Editing a comment
      No, the same result.
      Do you know any other method to get the last windows-update-date?
      Thank you!
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    Try escaping the double-quotes ("):
    Code:
    system.run[PowerShell.exe -nologo -command \"(Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)\"]

    Comment

    • piti87
      Junior Member
      • Jun 2020
      • 23

      #3
      Originally posted by dimir
      Try escaping the double-quotes ("):
      Code:
      system.run[PowerShell.exe -nologo -command \"(Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)\"]

      Thank you!
      I try this. It will work without any errors now, but the result is not the date:

      Result:
      (Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)

      Comment

      • dimir
        Zabbix developer
        • Apr 2011
        • 1080

        #4
        Perhaps it needs the escape symbol to be passed further then, try with triple backslashes:
        Code:
        system.run[PowerShell.exe -nologo -command \\\"(Install-Module -Name PSWindowsUpdate -Force; Get-WUHistory | Select-Object -first 1 | Select -ExpandProperty Date)\\\"]

        Comment


        • piti87
          piti87 commented
          Editing a comment
          No, the same result.
          Do you know any other method to get the last windows-update-date?
          Thank you!
      • piti87
        Junior Member
        • Jun 2020
        • 23

        #5
        Okay it works, tanks. There was a refresh-error. Big thanks!

        Comment

        Working...