4 ms·
I'm using this to test for return of service: $loop = "loop" do {$response = $null; Start-Sleep -Seconds 5 try {$response = Invoke-WebRequest "https://
by imperialdrive 6y ago
I'm using this to test for return of service:
$loop = "loop"
do {$response = $null; Start-Sleep -Seconds 5
try {$response = Invoke-WebRequest "https://login.microsoftonline.com/common/oauth2/ https://login.microsoftonline.com/common/oauth2/" -ErrorAction SilentlyContinue | select status*}
catch {Write-Host "Down $(get-date)"} finally {}
if ($response) {Write-Host "OK" ($response).StatusCode (Get-Date)}
} while ($loop -eq "loop")
- joenathanone 6y agoDoesn't work for me, I get: At line:1 char:16 + $loop = "loop" do {$response = $null; Start-Sleep -Seconds 5 try {$re ... + ~~ Unexpected token 'do' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
- imperialdrive 6y agoSorry about that - I have no idea how to format comments. I placed a copy here: https://www.codepile.net/pile/gz77EXzd https://www.codepile.net/pile/gz77EXzd
- joenathanone 6y agoThis version works for me, thank you :-)
- douglasrank 6y agoCleaned-up version while ($true) { $response = $null; try { $response = Invoke-WebRequest "https://login.microsoftonline.com/common/oauth2/ https://login.microsoftonline.com/common/oauth2/" -ErrorAction SilentlyContinue | select status*; if ($response) { "OK $($response.StatusCode) $(Get-Date)" | Write-Host; } } catch { "Down $(Get-Date)" | Write-Host; }; Start-Sleep -Seconds 5; }
- joenathanone 6y agoThank you, that works.
- imperialdrive 6y agoAhh, thank you. I simply dabble in PS on the side and write util-like scripts as a brain stretch. This is the first time I've ever had someone look at and 'clean' anything... much appreciated.