What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell script returning no result for PRTG

Votes:

0

I have a PS Script where I am trying to return data for status from Horizon pools. I get data when I run the script in the ISE window, but when running from PRTG in the sensor log I only get <prtg> </prtg? returned. The modules are all located within the powershell directories (I ran across another post), but still no dice. Any ideas?

Here is the script:

param (
    [string]$HVServer="",
    [string]$HVUser="",
    [string]$HVPass="",
    [string]$HVPoolID = ""
)

if ($HVPoolID -ne "")
{
    Import-Module VMware.VimAutomation.Core
    Import-Module VMware.VimAutomation.HorizonView
    if ($HVUser -eq "" -or $HVPass -eq "") { $con = Connect-HVServer -Server $HVServer  }
    else { $con = Connect-HVServer -Server $HVServer -User $HVUser -Password $HVPass }
    $viewAPI = $con.ExtensionData
    $query_Service = New-Object "Vmware.Hv.QueryServiceService"
    $query = New-Object "Vmware.Hv.QueryDefinition"
    $query.QueryEntityType = 'DesktopSummaryView'
    $Pools = $query_Service.QueryService_Query($viewAPI,$query)
    write-host "<prtg>"
    foreach($dp in $Pools.Results)
    {
        if ($dp.DesktopSummaryData.Name -eq $HVPoolID)
        {
            if ($dp.DesktopSummaryData.Type -ne "RDS")
            # no usage calculation for RDS types
            {
                $usage = $dp.DesktopSummaryData.NumSessions / $dp.DesktopSummaryData.NumMachines * 100
                write-host "  <result>"
                write-host "    <channel>Usage</channel>"
                write-host "    <value>$usage</value>"
                write-host "    <unit>percent</unit>"
                write-host "    <float>1</float>"
                write-host "    <DecimalMode>Auto</DecimalMode>"
                write-host "    <limitMode>1</limitMode>"
                write-host "    <LimitMaxWarning>85</LimitMaxWarning>"
                write-host "    <LimitMaxError>95</LimitMaxError>"
                write-host "  </result>"
            }
                        
            write-host "  <result>"
            write-host "    <channel>$($dp.DesktopSummaryData.Name) Sessions</channel>"
            write-host "    <value>$($dp.DesktopSummaryData.NumSessions)</value>"
            write-host "    <unit>count</unit>"
            write-host "  </result>"

            write-host "  <result>"
            write-host "    <channel>$($dp.DesktopSummaryData.Name) Machines</channel>"
            write-host "    <value>$($dp.DesktopSummaryData.NumMachines)</value>"
            write-host "    <unit>count</unit>"
            write-host "  </result>"

            write-host "  <result>"
            write-host "    <channel>Desktop Enabled</channel>"
            if ($dp.DesktopSummaryData.Enabled) {write-host "    <value>1</value>"} else{write-host "    <value>2</value>"}
            write-host "    <unit>Custom</unit>"
            write-host "    <ValueLookup>prtg.standardlookups.yesno.stateyesok</ValueLookup>"
            write-host "  </result>"

            if ($dp.DesktopSummaryData.Type -ne "RDS")
            # Provisioning is disabled for RDS type
            {
                write-host "  <result>"
                write-host "    <channel>Provisioning Enabled</channel>"
                if ($dp.DesktopSummaryData.ProvisioningEnabled) {write-host "    <value>1</value>"} else{write-host "    <value>2</value>"}
                write-host "    <unit>Custom</unit>"
                write-host "    <ValueLookup>prtg.standardlookups.yesno.stateyesok</ValueLookup>"
                write-host "  </result>"
            }

            if ($dp.DesktopSummaryData.Type -eq "RDS")
            {
                # match RDS Id with RDSServerSummaryView to get status of RDS servers in farm
                # used to detect if RDS server agent unreachable status
                $query_Service2 = New-Object "Vmware.Hv.QueryServiceService"
                $query2 = New-Object "Vmware.Hv.QueryDefinition"
                $query2.QueryEntityType = 'RDSServerSummaryView'
                $filter2 = new-object VMware.Hv.QueryFilterEquals -Property @{'memberName' = 'base.desktop'; 'value' = $dp.Id}
                $query2.Filter=$filter2
                
                $Farms = $query_Service2.QueryService_Query($viewAPI,$query2)
                
                write-host "  <result>"
                write-host "    <channel>Status</channel>"
                if ($Farms.Results[0].RuntimeData.Status -eq "AVAILABLE") {write-host "    <value>1</value>"}
                else { write-host "    <value>0</value>"}
                write-host "    <unit>Custom</unit>"
                write-host "    <ValueLookup>prtg.standardlookups.offon.stateonok</ValueLookup>"
                write-host "  </result>"
            }
        }
    }
    write-host "</prtg>"

    # disconnect from our connection server
    $con | Disconnect-HVServer -Force -Confirm:$false
}

custom powershell script

Created on Oct 12, 2022 5:15:43 PM

Last change on Oct 13, 2022 1:57:57 PM by  Felix Wiesneth [Paessler Support]



1 Reply

Votes:

0

Hello,

I recommend to expand the script with debug output written to a log file. Please place that output file in a folder like C:\Temp because the folder where the script itself is located, is usually protected.

As for testing in ISE, please use the 32-bit Powershell variant as PRTG's probe service is 32 bit and runs the 32-bit Powershell.

Created on Oct 14, 2022 1:48:56 PM by  Arne Seifert [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.