Experts, my PowerShell Do Until Script below is not Sending any HTTP Status Code to Console, even though I have told it do so. The output is blank. It does run without error. I can't figure out how to get the status code outputted to console. Note: The host notexist.nowhere.com below is intentionally wrong. It's there only for testing.
$url = "http://localhost"
$Header = @{Host = "notexist.nowhere.com"; "Pragma" = "no-cache"; "Cache-Control" = "no-cache, no-transform"}
$i = 1
Do{
Try {
$SC = (Invoke-RestMethod -Method POST -Uri $url -Headers $header -ErrorAction Stop ).StatusCode
}
catch {
$SC = ( $_.Exception.Response.StatusCode.value__ )
}
Write-host($SC) -ForegroundColor Red -BackgroundColor Cyan
$clipboard += $SC
$i++
} Until( $SC -eq 200 -or $i -gt 2 )
# Until($i -gt 10)
until (($SC -eq 200) -or ($i -gt 2))