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 }
Add comment