Wednesday, February 3, 2021

Check a site changes in PowerShell

I am in the process of purchasing a new backpack. As part of this process, I have been working with the MFG on a date for when their new pack is coming out. Instead of hitting the site X times a day, this simple PowerShell script monitors for changes on a specific page. There are several sites out there which do this for you, but they normally charge. Yeah, they are a bit more fancy and allow change regions, but I need to detect a simple change. So, here it is:

$checkUrl    = "https://somesite/products/packs/"
$checkMin    = 30
$origcontent = Invoke-WebRequest -Uri $checkUrl -Method Get

do {
    
    $content = Invoke-WebRequest -Uri $checkUrl -Method Get

    if ($content.Content -eq $origcontent.Content){
        Write-Verbose "Page contents are the same, sleeping.." -Verbose
        Start-Sleep -Seconds ($checkMin*60)
    }else{
        Write-Host "Page difference detected, exiting!" -ForegroundColor Green
        break
    }

} while ($true)

No comments:

Post a Comment