Functions/Set-AIMConfiguration.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
Function Set-AIMConfiguration {
    <#
    .SYNOPSIS
    Sets a variable in the script scope which holds default values for CLIPasswordSDK operations.
    Must be run prior to other module functions if path to CLIPasswordSDK has not been previously set.

    .DESCRIPTION
    Sets properties on an object which is used as the value of a variable in the script scope.
    The created variable can be queried and used by other module functions to provide default values.
    Creates a file in the logged on users home folder named AIMConfiguration.xml. This file contains the variable
    used by the module, and will be imported with the module into the module's scope.

    .PARAMETER ClientPath
    The path to the CLIPasswordSDK.exe utility

    .EXAMPLE
    Set-AIMConfiguration -ClientPath D:\Path\To\CLIPasswordSDK.exe

    Sets default path to CLIPasswordSDK to D:\Path\To\CLIPasswordSDK.exe.
    This is accessed via the variable property $Script:AIM.ClientPath
    Creates C:\users\user\AIMConfiguration.xml file to hold values for persistence.

    #>

    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateScript( { Test-Path $_ -PathType Leaf })]
        [ValidateNotNullOrEmpty()]
        [string]$ClientPath
    )

    Begin {

        $Defaults = [pscustomobject]@{ }

    }

    Process {

        If ($PSBoundParameters.Keys -contains "ClientPath") {

            $Defaults | Add-Member -MemberType NoteProperty -Name ClientPath -Value $ClientPath

        }

    }

    End {

        Set-Variable -Name AIM -Value $Defaults -Scope Script

        $Script:AIM | Select-Object -Property * | Export-Clixml -Path "$env:USERPROFILE\AIMConfiguration.xml" -Force

    }

}