There is some Power Shell script that returns content.
and it is called using the Powershell Web API:
Invoke-WebRequest -Headers $headers -Uri $CMHostname/-/script/v2/master/Get-TestContent?type=AllItems
Case 1
try
{
....
} catch {
Write-Host "Error: $_"
exit 402
# return 402
}
it is always returns HTTP code 200
Case 2 script like below, always return HTTP 500 and content 'The page cannot be displayed because an internal server error has occurred.'
try
{
....
throw "some error"
} catch {
Write-Host "Error: $_"
throw $_
}
Is it possible to return a specific HTTP code?