Ad Widget

Collapse

Powershell script execution as a UserParameter - working but not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • diezc
    Junior Member
    • May 2017
    • 2

    #1

    Powershell script execution as a UserParameter - working but not working

    Hi,
    For the past few days i've been trying to set up a userparameter under windows server 2008 r2 that runs a powershell script.
    I have this same userparameters and scripts running under windows server 2012R2 and working fine.

    My issue is, that when i execute the script from the cmd, i get the correct execution however whener it is called by the zabbix agent, i believe it is calling a 32bit version of powershell for wich some of my items just dont work. Has anyone had problems like this?

    Code:
    UserParameter=apppool.discovery,powershell -NoProfile -ExecutionPolicy Bypass -File "C:\ZabbixAgent\userparams_scripts\get_apppool.ps1"
    Running the script from the cmd works fine:

    Code:
    C:\ZabbixAgent\userparams_scripts>powershell -NoProfile -ExecutionPolicy Bypass
    -File get_apppool.ps1
    {
     "data":[
    
    { "{#APPPOOL}" : "borrar" },
    { "{#APPPOOL}" : "clasico2" },
    { "{#APPPOOL}" : "ws_predictor" }
    
     ]
    }
    
    C:\ZabbixAgent\userparams_scripts>
    However, when i call it using zabbix_get:

    Code:
    zabbix_get -s 10.XX.XX.34 -p 10050 -k site.discovery
    Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. Retrievi
    ng the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF0
    0DC944A6} failed due to the following error: 80040154.
    At C:\ZabbixAgent\UserParameterScripts\get_sites.ps1:2 char:23
    + $sites = Get-ChildItem <<<< -Path IIS:\Sites -Name
    + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterB
    indingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShe
    ll.Commands.GetChildItemCommand
    
    {
    "data":[
    
    { "{#SITE}" : "" }
    
    ]
    }
    How exactly does the zabbix agent call for cmd commands?
    Anyhelp will be welcome!
  • maco1717
    Junior Member
    • Apr 2019
    • 21

    #2
    Hi diezc,

    I'm experiencing exactly this, where did you get with this?

    Did you manage to get any progress?

    In my case, I'm trying to get a registry key...

    Code:
     zabbix_get -s city.elements.symplectic.org -k ps[]
    Get-ChildItem : Cannot find path 'HKEY_LOCAL_MACHINE\SOFTWARE\somekey'
    because it does not exist.
    At line:1 char:3
    + $(Get-ChildItem Registry::HKEY_LOCAL_MACHINE\SOFTWARE\somekey)
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKEY_LOCAL_MACHINE\SOFTWARE\somekey:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
    The funny thing is that this exact same thing works on some server and don't work on this one. I have check versions of PS, I have checked that the Key is in fact there and permissions all looks good.

    Can anyone assist with this?

    Kind regards and thanks.
    \M

    Comment

    • Radboud
      Junior Member
      • Mar 2019
      • 25

      #3
      Dear Maco1717,

      We ran into the same problem, and i saw your post on reddit.
      We solved this by switching to the 64bit agent downloaded from the zabbix website

      We are using the 4.0.6 agent MSI installer from https://www.zabbix.com/download_agents#tab:40LTS
      4.0.6 Windows (msi) amd64 OpenSSL 896c104d8ddb23ba69cdd5bc59f3e7f7
      Hope that this solves your problem.
      Good luck

      Radboud

      Comment

      • maco1717
        Junior Member
        • Apr 2019
        • 21

        #4
        Originally posted by Radboud
        Dear Maco1717,

        We ran into the same problem, and i saw your post on reddit.
        We solved this by switching to the 64bit agent downloaded from the zabbix website

        We are using the 4.0.6 agent MSI installer from https://www.zabbix.com/download_agents#tab:40LTS
        4.0.6 Windows (msi) amd64 OpenSSL 896c104d8ddb23ba69cdd5bc59f3e7f7
        Hope that this solves your problem.
        Good luck

        Radboud
        Thanks a lot radboud that worked.

        Comment

        Working...