DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
77 stars 18 forks source link

[New App Request] Microsoft Windows SDK (on To Do list) #76

Open AScott-WWF opened 4 months ago

AScott-WWF commented 4 months ago

This one was on your To Do List Microsoft appear to have rebranded the 'Microsoft Windows Desktop SDK' as 'Microsoft Windows SDK'

This will scrape the Windows SDK downloads page N.B. This will require the addition of the .iso format to the Type parameter in New-NeverGreenApp.ps1, this also makes use of the ReleaseDate Parameter introduced in the [Enhancement] Microsoft SSMS

The Script:

# Get-MicrosoftWindowsSDK.ps1

$AppName = "Microsoft Windows SDK"
$ReleaseUrl = "https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/"
[version]$Version = Get-Version -Uri $ReleaseUrl -Pattern 'The Windows SDK \((\d+\.\d+\.\d+)\) for Windows'

Write-Verbose "Obtaining $($AppName) Release Versions..."
# Fetch the HTML content of the webpage
$htmlContent = (Invoke-WebRequest -Uri $ReleaseUrl).Content

# Define the RegEx pattern to match the links and capture the version number and BaseURI
$Datepattern = "Build $($Version) \(released (.+?)\)"

# Return the Release Date if found
if ($htmlContent -match $Datepattern) {
    $ReleaseDate = Convert-DateFormat -DateString $matches[1] -OutputFormat "dd-MMM-yyyy" -InputLocale "en-US" # This requires new Convert-DateFormat function
} else {
    $ReleaseDate = "n/a"
}

$AppVersions = @(
    @{Version = $Version; Type = 'exe'; Language = 'English (United States)'; Pattern = 'Download the installer'; ReleaseDate = $ReleaseDate}
    @{Version = $Version; Type = 'iso'; Language = 'English (United States)'; Pattern = 'Download the \.iso'; ReleaseDate = $ReleaseDate}
)

foreach ($AppVersion in $AppVersions) {
    $SearchCount = 1 # This may need increasing as future versions are released
    $ThisVersionUri = Get-Link -Uri $ReleaseUrl -MatchProperty outerHTML -Pattern $AppVersion.Pattern

    do {
        if ($ThisVersionUri) {
            #Build each link with Language specific versions
            $URL = (Resolve-Uri -Uri $($ThisVersionUri)).Uri
            New-NevergreenApp -Name $AppName -Version $AppVersion.Version -Uri $URL -Architecture 'x64' -Language $AppVersion.Language -Type $AppVersion.Type -ReleaseDate $AppVersion.ReleaseDate
            break
        }

        $SearchCount--
    } until ($SearchCount -eq 0)

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for $($AppName) $($AppVersion.Architecture) $($AppVersion.Language)"
    }
}