Skip to content

Instantly share code, notes, and snippets.

@desek
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desek/5ba305ac26f61346f56e to your computer and use it in GitHub Desktop.
Save desek/5ba305ac26f61346f56e to your computer and use it in GitHub Desktop.
# 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