Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
Created January 9, 2017 19:46
Show Gist options
  • Save maxfridbe/3499bf1ab9ecb2260e9fc42914d98aeb to your computer and use it in GitHub Desktop.
Save maxfridbe/3499bf1ab9ecb2260e9fc42914d98aeb to your computer and use it in GitHub Desktop.
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