private/Find-ArticleUri.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
function Find-ArticleUri {

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [Array] $Article
    )

    Begin {
        $uriTemplate = 'http://www.catalog.update.microsoft.com/Search.aspx?q=KB{0}'
    }

    Process {
        foreach ($oneArticle in $Article) {
            [psCustomObject] @{
                articleId = $oneArticle.articleId

                version = $oneArticle.Text |
                    Select-String -allMatches -pattern '(?x) (\d+ \.){1,3} (\* | \d+)' |
                    ForEach-Object { $_.Matches.Value -as [Version] }

                uri = $uriTemplate -f $oneArticle.articleId
            }
        }
    }

    End {}
}