Post

Get Windows Update Information from Microsoft with PowerShell

Today I had the challenge to find information for a specific Windows Update.

I only know the KB number of that particular Windows Update but I wanted to get the following information:

  • Name of the Windows Update
  • The update information URL from Microsoft

So I wrote a PowerShell function for this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function Get-CHWindowsUpdateInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ValidateLength(1,9)]
        [string]
        $KB
    )

    # Build the search URL and get the results of
    # that query back.
    $SearchURL = [string]::Concat('https://support.microsoft.com/en-us/Search/results?query=', $KB)
    $result = Invoke-WebRequest -Uri $SearchURL

    # Searching for the Windows Update Link for that
    # specific KB.
    $URL = $result.Links |
    Where-Object { $_.outerHTML.Contains($KB) } |
    Select-Object -First 1 |
    Select-Object -ExpandProperty href

    # Searching for the Windows Update Name for that
    # specific KB.
    $Title = $result.Links |
    Where-Object { $_.outerHTML.Contains($KB) } |
    Select-Object -First 1 |
    Select-Object -ExpandProperty title

    # If both values are empty I will return $null
    # else I return the update information as a
    # PSCustomObject.
    if([string]::IsNullOrEmpty($URL) -and [string]::IsNullOrEmpty($URL)) {
        return $null
    } else {
        return [PSCustomObject]@{
            WindowsUpdateTitle = $Title
            WindowsUpdateURL   = $URL
        }
    }
}

This post is licensed under CC BY 4.0 by the author.