private/Find-AssetGuid.ps1

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
function Find-AssetGuid {
    <#
        Find GUIDs of all asset types for selected Build update
    #>

        [CmdletBinding()]
        Param(
            [Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )]
            [String] $article
        )

    Begin {
        # Endpoint for searching article by its ID
        $updateCatalogSearchLink =   'http://www.catalog.update.microsoft.com/Search.aspx?q=KB{0}'
    }

    Process {
        $articleUri = $updateCatalogSearchLink -f $article

        (Invoke-WebRequest -Uri $articleUri).Links |
            Where-Object id -like '*_link' |
            Select-Object @{
                    Name = 'id'
                    Expression = { $_.Id -replace '_link', '' }
                },
                class,
                innerText,
                href
    }

    End {}

}