Custom Monitor output identical to what is expected, but treated as "Unknown"

by Nov 15, 2017

I created a custom service monitor to check on which node a clustered SQL server is running.
The cluster name is the argument passed to the script.  
The script name is the complete path to the .BAT file below, which calls a .PS1 powershell script.

Get-HostName.bat file:

@echo off
set remotesrv=%1
powershell.exe -executionpolicy bypass -noprofile -file "C:Program Filesuptime softwareuptimepluginsscriptsGet-HostNameGet-HostName.ps1" %remotesrv%


Get-Hostname.ps1 file:
Invoke-Command -Computername $RemoteServer -ScriptBlock {$Env:COMPUTERNAME}

The Output is the server name.  I have used various comparisons (is equal to, contains, regex), but the results always come back "UNKNOWN", even though the message and output display the server name as expected.

I've also tried several permutations of the powershell script, such as
1.  Changing the scriptblock to {write-output $env:computername}
2.  Passing the results of the Invoke-Command to a variable and displaying that variable:  $A = Invoke-Command…;  Write-Output $A

In every case the comparison fails.  I'm using uptime v7.8.3 build 3.