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

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 Files\uptime software\uptime\plugins\scripts\Get-HostName\Get-HostName.ps1" %remotesrv%
<NUL

 

Get-Hostname.ps1 file:
param(
$RemoteServer="localhost"
)
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.

  • Changed the .BAT file to
    @echo off
    set remotesrv=%1
    powershell.exe -executionpolicy bypass -noprofile -file "C:\Program Files\uptime software\uptime\plugins\scripts\Get-HostName\Get-HostName.ps1" %remotesrv%
    EXIT %ERRORLEVEL%
    <NUL

    Once the EXIT command was added, the script started working correctly.