Ad Widget

Collapse

system.run powershell script not returning values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aitor555
    Junior Member
    • Apr 2014
    • 6

    #1

    system.run powershell script not returning values

    Hello,

    I am running the following powershell script to get drive E: fragmentation percentage:

    $drive = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'E:'"
    $result = $drive.DefragAnalysis()
    if ($result.ReturnValue -eq 0)
    {
    $result.DefragAnalysis.FilePercentFragmentation
    }

    Zabbix Item:
    system.run[powershell.exe -command c:\zabbix\scripts\fragmentacion_e.ps1]

    It works OK but when I try to get the same info for drive C: I get no value. I have run the script directly in the machine I am monitoring and it works OK.

    I have also checked agent log (LogRemoteCommands=1) and the script is executed but no value is displayed in Zabbix "Latest data".

    Any ideas?

    Thanks in advance.
  • coreychristian
    Senior Member
    Zabbix Certified Specialist
    • Jun 2012
    • 159

    #2
    Is the script timing out?

    One thing to check, would be if the script takes a lot longer to respond when querying the C drive vs the E drive. You would need to look at the timeout settings on the zabbix server and agent.

    Comment

    • aitor555
      Junior Member
      • Apr 2014
      • 6

      #3
      Hello coreychristian,

      I changed the agent timeout to 30 before running my first powershell script. I don't know how to change it on the server.
      When I run the scripts in the target server it takes similar time for both drives.

      I tested to redirect script output to a text file to check whether the script is executed by zabbix agent correctly and it works OK:

      $result.DefragAnalysis.FilePercentFragmentation >> fragmentation_drive_c.txt

      I can't figure out what is the problem.

      Thank you.

      Comment

      • aitor555
        Junior Member
        • Apr 2014
        • 6

        #4
        Changing server timeout solved the issue.

        Thanks coreychristian.

        Comment

        • seanwasere
          Junior Member
          • May 2012
          • 12

          #5
          I got it to work by adding

          Code:
          Write-Output $result
          to the end of your script.

          so it now looks like

          Code:
          $drive = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = 'E:'"
          $result = $drive.DefragAnalysis()
          if ($result.ReturnValue -eq 0) {
              $result.DefragAnalysis.FilePercentFragmentation
          }
          Write-Output $result

          Comment

          Working...