Last active
August 29, 2015 14:07
-
-
Save desek/5ba305ac26f61346f56e to your computer and use it in GitHub Desktop.
This file contains 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
# Modified version of http://poshcode.org/5474 by @sorlov | |
function DoSomething {} | |
function Check-WindowsPreview | |
{ | |
PARAM( | |
[int]$Sleep=10, | |
[switch]$WaitForIt | |
) | |
BEGIN | |
{ | |
do | |
{ | |
try | |
{ | |
$startTime = Get-Date | |
$output = Invoke-WebRequest -Method Get -Uri "http://preview.windows.com" -UserAgent "Powershell Script" -UseBasicParsing | |
$endTime = Get-Date | |
if ($output.Content -match "so please check back soon") | |
{ | |
$Props = [ordered]@{ | |
Released = "NotYet" | |
StartTime = $startTime | |
EndTime = $endTime | |
Duration = ($endTime - $startTime).TotalSeconds | |
} | |
New-Object -TypeName PSObject -Property $Props | |
} | |
else | |
{ | |
$Props = [ordered]@{ | |
Released = "Yes" | |
StartTime = $startTime | |
EndTime = $endTime | |
Duration = ($endTime - $startTime).TotalSeconds | |
} | |
New-Object -TypeName PSObject -Property $Props | |
$WaitForIt = $false | |
DoSomething | |
} | |
} | |
catch | |
{ | |
$Props = [ordered]@{ | |
Released = "Unknown: $($_.Exception.Message)" | |
StartTime = $startTime | |
EndTime = $endTime | |
Duration = ($endTime - $startTime).TotalSeconds | |
} | |
New-Object -TypeName PSObject -Property $Props | |
} | |
if ($WaitForIt) { Start-Sleep -Seconds $Sleep } | |
} | |
while ($WaitForIt) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment