functions/get-d365lcsuploadconfig.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
62
63
64
65
66
67

<#
    .SYNOPSIS
        Get the LCS configuration details
         
    .DESCRIPTION
        Get the LCS configuration details from the configuration store
         
    .PARAMETER OutputType
        The output type you want the cmdlet to return to you
         
        Default value is "HashTable"
         
        Valid options:
        HashTable
        PSCustomObject
         
    .EXAMPLE
        PS C:\> Get-D365LcsUploadConfig
         
        This will return the saved configuration for accessing the LCS API.
        The object return will be a HashTable.
         
    .EXAMPLE
        PS C:\> Get-D365LcsUploadConfig -OutputType "PSCustomObject"
         
        This will return the saved configuration for accessing the LCS API.
        The object return will be a PSCustomObject.
         
    .NOTES
        Tags: Environment, Url, Config, Configuration, LCS, Upload, ClientId
         
        Author: Mötz Jensen (@Splaxi)
         
#>


function Get-D365LcsUploadConfig {
    [CmdletBinding()]
    [OutputType()]
    param (
        [Parameter(Mandatory = $false, Position = 1)]
        [ValidateSet("HashTable", "PSCustomObject")]
        [string] $OutputType = "HashTable"
    )
    Invoke-TimeSignal -Start

    $res = [Ordered]@{}

    Write-PSFMessage -Level Verbose -Message "Extracting all the LCS configuration and building the result object."

    foreach ($item in (Get-PSFConfig -FullName d365fo.tools.lcs*)) {
        $nameTemp = $item.FullName -replace "^d365fo.tools.lcs.upload.", ""
        $name = ($nameTemp -Split "\." | ForEach-Object { (Get-Culture).TextInfo.ToTitleCase($_) } ) -Join ""
        
        $res.$name = $item.Value
    }

    if ($OutputType -eq "HashTable") {
        $res
    }
    else {
        $res | ConvertTo-PsCustomObject
    }

    Invoke-TimeSignal -End

}