Public/Set-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
55
56
57
58
59
60
61
function Set-MDSConfiguration {
    <#
    .SYNOPSIS
    Set module configuration variables

    .DESCRIPTION
    Some functions in the module require variables that are unique to the environment. This function allows for the setting of those variables. Supported variables may be tab completed with the name parameter. Those variables include:
        ADConnectServer (Start-MDSADSyncSyncCycle)
        SkypeOnPremServer (Import-MDSSkypeOnPrem)

    .PARAMETER Name
    Valid values: ADConnectServer, SkypeOnPremServer

    .PARAMETER Value
    String value for the variable specified in the name parameter

    .EXAMPLE
    Set-MDSConfiguration -Name ADConnectServer -Value AADConnect.contoso.com

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

    #>

    [cmdletbinding()]
    param(
        [ValidateSet("ADConnectServer","SkypeOnPremServer")]
        [Parameter(Mandatory)]
        [String]$Name,

        [Parameter(Mandatory)]
        [String]$Value
    )
    begin {}
    process {
        Try {
            $Configuration = Import-Configuration -ErrorAction Stop
            If ($null -ne $Configuration) {
                If ($Configuration[$Name]) {
                    Write-Verbose 'Removing old value'
                    $Configuration.Remove($Name)
                }

                Write-Verbose 'Adding old value'
                $Configuration.Add($Name,$Value)
                Get-Module MDSTools -ErrorAction Stop |
                    Export-Configuration $Configuration -Scope Enterprise -ErrorAction Stop
            }
            Else {
                Write-Verbose "Exporting new value"
                $FirstEntry = @{$Name = $Value}
                Get-Module MDSTools -ErrorAction Stop |
                    Export-Configuration $FirstEntry -Scope Enterprise -ErrorAction Stop
            }
        }
        Catch {
            Write-Error $PSItem
        }
    }
    end {}
}