Im monitoring a web service with powershell.
My webservice returns "ON" or "OFF" if a Hardware Controller device is Online or not.
My statistic is the time the script takes to find the controller (if ON) and it should have status DOWN on Orion when the web service returns OFF.
Im new to powershell, my script calls the web service, get the status back and present the statistic,, but I cannot get it to exit properly.
My script is:
=======================================
$control = New-WebServiceProxy -uri "https://test-company.net/webservice/Controller?wsdl" -Namespace ns1 -Class class1;
$sw = [Diagnostics.Stopwatch]::StartNew();
$status = $control.getMachineX('test-company.net', 'Passwd1','1').controlResponse.status;
$sw.Stop();
[decimal]$elapsed = [Math]::Round(($sw.Elapsed.TotalSeconds), 3);
Write-Host 'Statistic.Elapsed: ' $elapsed;
[bool]$state = $false;
if ($status -eq 'ON') {
$state = $true;
}
else {$state = $false};
Write-Host $state;
if ($state -eq $true) {
write-host IS TRUE;
Exit 0
}
else {Write-Host IS FALSE;
Exit 1
};
=======================================
The problem is the last 7 lines.
I dont know how to convert the status (ON or OFF) to boolean, and then make the script exit with (0) or (1) depending of the boolean (true or false)
My question boils to:
- How can I make the script exit (0) or exit (1) depending on the value returned from a boolean variable.?
Thanks guys!!
Dotty