public/Get-SpeedTestConfig.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
function Get-SpeedTestConfig {
    <#
        .SYNOPSIS
        Get the default server configurations for Internet and Local speed test servers.

        .DESCRIPTION
        Get the default server configurations for Internet and Local speed test servers.

        .EXAMPLE
        Get-SpeedTestConfig
    #>


    [CmdletBinding()]
    Param()

    try {
        Write-Verbose -Message 'Getting content of config.json and returning as a PSCustomObject.'
        $config = Get-Content -Path "$PSScriptRoot\config.json" -ErrorAction 'Stop' | ConvertFrom-Json

        $config = [PSCustomObject] @{
            DefaultInternetServer = $config.defaultInternetServer.defaultServer;
            DefaultInternetPort   = $config.defaultInternetServer.defaultPort;
            DefaultLocalServer    = $config.defaultLocalServer.defaultServer;
            DefaultLocalPort      = $config.defaultLocalServer.defaultPort;
        }

        return $config
    } catch {
        throw "Can't find the JSON configuration file. Use 'Set-SpeedTestConfig' to create one."
    }
}