Created
January 9, 2017 19:46
-
-
Save maxfridbe/3499bf1ab9ecb2260e9fc42914d98aeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wait-websiteup($testUrl, $timeoutSeconds){ | |
$webClient = new-object System.Net.WebClient | |
$webClient.Headers.Add(“user-agent”, “PowerShell Script”) | |
$startTime = get-date | |
while (1 -eq 1) { | |
$output = “” | |
try{ | |
$output = $webClient.DownloadString($testUrl) | |
} catch { | |
Write-Warning "Waiting..." | |
} | |
$endTime = get-date | |
$s = ($endTime – $startTime).TotalSeconds | |
if($s -gt $timeoutSeconds){ | |
Write-Error "Timed out waiting for $testUrl" | |
break | |
} | |
if( -not [string]::IsNullOrWhiteSpace($output) ){ | |
Write-verbose "Site Up $testUrl" -Verbose | |
break | |
} | |
Start-Sleep -Seconds 3 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment