Public/Get-WacFeed.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 Get-WacFeed
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [String]
        $GatewayEndpoint,

        [Parameter()]
        [PSCredential]
        $Credential
    )

    $params = @{
        GatewayEndpoint = $GatewayEndpoint
        APIEndpoint = '/api/extensions/configs'
        Method = 'Get'
    }

    if ($Credential)
    {
        $params.Add('Credential',$Credential)
    }

    Write-Verbose -Message 'Generating request parameters ...'
    $requestParameters = Get-RequestParameter @params

    Write-Verbose -Message 'Invoking get WAC feed api ...'
    $response = Invoke-WebRequest @requestParameters -ErrorAction SilentlyContinue
    if ($response.StatusCode -eq 200)
    {
        $feeds = ConvertFrom-Json -InputObject $response.Content

        $feedObject = @()
        foreach ($feed in $feeds.packageFeeds)
        {
            $feedHash = [PsCustomObject]@{
                Path = $feed
            }

            $feedObject += $feedHash
        }

        return $feedObject
    }
    else
    {
        throw 'Error invoking get WAC feed api ...'
    }
}