Internal/functions/Get-DssConfig.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
function Get-DssConfig {
    <#
    .SYNOPSIS
        Gets the test config from the specified folder
    
    .PARAMETER ConfigPath
        Location of the configuration file. May be on a filepath or a URL
    #>

    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [string[]]$ConfigPath
    )
    begin {}
    process {}
    end {
        $objConfig = @()
        Foreach ($config in $ConfigPath){
            Write-Verbose -Message "Fetching $config"
            if ($config -match '^http.*') {
                $response = Invoke-WebRequest $config
                if ($response.StatusCode -eq '200') {
                    $content = $response.content
                } else {
                    Write-Warning -Message "Could not get content from $config"
                }
            } else {
                if (Test-Path $config) {
                    $content = Get-Content $config -Raw
                } else {
                    Write-Warning -Message "Could not get content from $config"
                }
            }
            $objConfig += ConvertFrom-Json -InputObject $content
        }
        $objConfig  
    }
}