I have the following PowerShell Script to check on a Horizon View Connection Server:
#
# Retrieve status of VMware Horizon Connection Servers
#
# set some parameters with default values
param (
[string]$HVServer="server",
[string]$HVUser="user",
[string]$HVPass="password",
[string]$HVFilter="*"
)
# if no $HVServer specified, don't do anything
if ($HVServer -ne "")
{
#import necessary modules
Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.HorizonView
# if no user/pass specified via parameters, prompt for user/pass, else use the parameters
if ($HVUser -eq "" -or $HVPass -eq "") { $con = Connect-HVServer -Server $HVServer }
else { $con = Connect-HVServer -Server $HVServer -User $HVUser -Password $HVPass }
# connect to the Horizon View API
$viewAPI = $con.ExtensionData.ConnectionServerHealth.ConnectionserverHealth_List()
# Start XML output for PRTG
write-host "<prtg>"
# loop through all connection servers
foreach($cs in $viewAPI)
{
# check if Name matches filter specified
if ($cs.Name -like $HVFilter)
{
# Get Connection Server status
write-host " <result>"
write-host " <channel>$($cs.Name) STATUS</channel>"
if ($cs.Status -eq "OK") {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>"
# Get Connection Server current connections
write-host " <result>"
write-host " <channel>$($cs.Name) # Connections</channel>"
write-host " <value>$($cs.ConnectionData.NumConnections)</value>"
write-host " <unit>Count</unit>"
write-host " </result>"
# Get Connection Server current Composer connections
write-host " <result>"
write-host " <channel>$($cs.Name) # Composer Connections</channel>"
write-host " <value>$($cs.ConnectionData.NumViewComposerConnections)</value>"
write-host " <unit>Count</unit>"
write-host " </result>"
# Get Connection Server tunneled connections
write-host " <result>"
write-host " <channel>$($cs.Name) # Tunneled Connections</channel>"
write-host " <value>$($cs.ConnectionData.NumTunneledSessions)</value>"
write-host " <unit>Count</unit>"
write-host " </result>"
# Get Connection Server PCoIP Secure Gateway connections
write-host " <result>"
write-host " <channel>$($cs.Name) # PSG Connections</channel>"
write-host " <value>$($cs.ConnectionData.NumPSGSessions)</value>"
write-host " <unit>Count</unit>"
write-host " </result>"
}
}
# close XML for PRTG output
write-host "</prtg>"
# disconnect from our connection server
$con | Disconnect-HVServer -Force -Confirm:$false
}
exit 0
I get the following result when I run the script on the probe:
<prtg>
<result>
<channel>VIEWCON-201 STATUS</channel>
<value>1</value>
<unit>Custom</unit>
<ValueLookup>prtg.standardlookups.yesno.stateyesok</ValueLookup>
</result>
<result>
<channel>VIEWCON-201 # Connections</channel>
<value>18</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-201 # Composer Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-201 # Tunneled Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-201 # PSG Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-202 STATUS</channel>
<value>1</value>
<unit>Custom</unit>
<ValueLookup>prtg.standardlookups.yesno.stateyesok</ValueLookup>
</result>
<result>
<channel>VIEWCON-202 # Connections</channel>
<value>23</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-202 # Composer Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-202 # Tunneled Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
<result>
<channel>VIEWCON-202 # PSG Connections</channel>
<value>0</value>
<unit>Count</unit>
</result>
</prtg>
I created a new sensor (EXE/Script Advanced Sensor) and enabled "Store result in case of error".
If I look in the "result of sensor 12345.txt" file it just has one Line:
NUL NUL NUL NUL ... etc.
The file "result of sensor 12345.Data.txt contains the following:
Data['linuxloginpassword'].asString := '***';
Data['notonpod'].asString := '0';
Data['fastcount'].asString := '0';
Data['lastmsg'].asString := '#Y2 Junk after document element </prtg> @#O231[No mapping for the Unicode character exists in the target multi-byte code page]';
Data['resultfile'].asString := 'Result of Sensor 17412.txt';
Data['windowsloginusername'].asString := 'ruladmin';
Data['hostv6'].asString := '::1';
Data['exefile'].asString := 'ConnServerStatus.ps1';
Data['lastuptime'].asString := '0';
Data['writeresult'].asString := '2';
Data['blockedsens'].asString := '';
Data['reqmsginterval'].asString := '60';
Data['windowslogindomain'].asString := 'rul.gmbh';
Data['tlsexplicit_imap'].asString := '';
Data['channelnames'].asString := '';
Data['tlsexplicit_default'].asString := '';
Data['canlinux'].asString := '0';
Data['isexesensor'].asString := '1';
Data['windowsloginpassword'].asString := '***';
Data['environment'].asString := '';
Data['mutexname'].asString := '';
Data['channelinfos'].asString := '{}';
Data['uptimecount'].asString := '0';
Data['vmwareparams'].asString := '1';
Data['reboot'].asString := '44698.8894467593';
Data['usednstime'].asString := '0';
Data['newpowershell'].asString := '0';
Data['linuxlogindomain'].asString := '';
Data['exeparamshash'].asString := 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Data['tlsexplicit_port'].asString := '';
Data['monitorchange'].asString := '';
Data['inerror'].asString := '1';
Data['sensorid'].asString := '17412';
Data['ipversion'].asString := '0';
Data['tlsexplicit_smtp'].asString := '';
Data['host'].asString := '127.0.0.1';
Data['usewindowsauthentication'].asString := '0';
Data['simulate'].asString := '0';
Data['tlsexplicit_ftp'].asString := '';
Data['timeout'].asString := '120';
Data['exeparams'].asString := '';
Data['momopersistent'].asString := '';
Data['tlsexplicit_pop3'].asString := '';
I already googled a lot of possible solutions. So far I did not get this to work.
Any help would be appreciated
I found a solution. The necessary modules have to be installed in path for all users.
That would be: “C:\Program Files\WindowsPowerShell\Modules”
After I copied the 2 Modules (“VMware.VimAutomation.Core” and “VMware.VimAutomation.HorizonView”) to that directory, everything worked fine.
I still have to find out, why the modules did not get installed in that directory in the first place.
May, 2022 - Permalink