Public/Get-PSSlackConfig.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
Function Get-PSSlackConfig {
    <#
    .SYNOPSIS
        Get PSSlack module configuration.
 
    .DESCRIPTION
        Get PSSlack module configuration
 
    .PARAMETER Source
        Get the config data from either...
         
            PSSlack: the live module variable used for command defaults
            PSSlack.xml: the serialized PSSlack.xml that loads when importing the module
 
        Defaults to PSSlack
 
    .FUNCTIONALITY
        Slack
    #>

    [cmdletbinding()]
    param(
        [ValidateSet("PSSlack","PSSlack.xml")]
        $Source = "PSSlack"
    )
    
    if($Source -eq "PSSlack")
    {
        $Script:PSSlack
    }
    else
    {
        function Decrypt {
            param($String)
            if($String -is [System.Security.SecureString])
            {
                [System.Runtime.InteropServices.marshal]::PtrToStringAuto(
                    [System.Runtime.InteropServices.marshal]::SecureStringToBSTR(
                        $string))
            }
        }
        Import-Clixml -Path "$ModuleRoot\PSSlack.xml" |
            Select -Property ArchiveUri,
                         @{l='Uri';e={Decrypt $_.Uri}},
                         @{l='Token';e={Decrypt $_.Token}}
    }

}