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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function Find-AssetGuid {
    <#
        Find GUIDs of all asset types for KB article specified by its Uri
    #>


    [CmdletBinding()]
        Param(
            [Parameter(
                HelpMessage = 'Microsoft KnowledgeBase article Uri.',
                Mandatory,
                Position = 0,
                ValueFromPipeline,
                ValueFromPipelineByPropertyName
            )]
            [Alias( 'Uri' )]
            [String[]] $articleUri
        )

    Begin {}

    Process {
        foreach ($oneUri in $articleUri) {
            (Invoke-WebRequest -Uri $oneUri).Links |
            Where-Object id -like '*_link' |
            Select-Object @{
                    Name = 'GUID'
                    Expression = { $_.Id -replace '_link', '' }
                },
                @{
                    Name = 'platform'
                    Expression = {
                        if( $_.innerText -match '\b(x86|x64|arm64)\b' ) {
                            $Matches[1].ToLower()
                        }
                    }
                },
                @{
                    Name = 'type'
                    Expression = {
                        if( $_.innerText -match '\b(Cumulative|Delta)\b' ) {
                            $Matches[1].ToLower()
                        }
                    }
                },
                class,
                innerText,
                href
        }
    }

    End {}

}