Public/Get-MDSConfiguration.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-MDSConfiguration {
    <#
    .SYNOPSIS
    Set module configuration variables

    .DESCRIPTION
    Some functions in the module require variables that are unique to the environment. This function displays the configuration variables.

    .EXAMPLE
    Get-MDSConfiguration

    List the module configuration file

    .NOTES
    Uses the 'Configuration' module by Joel Bennett (https://www.powershellgallery.com/packages/Configuration)

    #>


    [CmdletBinding()]
    param (
        [ValidateSet('ADConnectServer','SkypeOnPremServer','ErrorTest')]
        [Parameter()]
        [String]$Setting
    )

    begin {}
    process {
        Try {
            $Configuration = Import-Configuration -ErrorAction Stop

            # Return the specified setting
            If ($PSBoundParameters.Setting) {
                $ConfigSetting = $Configuration[$Setting]
                If (-not $ConfigSetting) {
                    Throw "The module configuration does not have $Setting configured. Use 'Set-MDSConfiguration -Name $Setting -Value <string>' to configure your settings."
                }
                $ConfigSetting
            }
            # Throw an error if no settings are set
            ElseIf ($Configuration.count -eq 0) {
                Throw "Thank you for using the MDS Tools module. Please run Set-MDSConfiguration to configure the module settings."
            }
            # Return all settings
            Else {
                $Configuration
            }
        }
        Catch {
            Write-Error $PSItem
        }
    }
    end {}
}