internal/Set-Config.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
<#
.SYNOPSIS
    Set Configuration
.EXAMPLE
    PS C:\>Set-Config
    Set Configuration
.INPUTS
    System.String
#>

function Set-Config {
    [CmdletBinding()]
    #[OutputType([object])]
    param (
        # Application Insights Telemetry Disabled
        [Parameter(Mandatory = $false)]
        [bool] $AIDisabled,
        # Application Insights Instrumentation Key
        [Parameter(Mandatory = $false)]
        [string] $AIInstrumentationKey,
        # Application Insights Ingestion Endpoint
        [Parameter(Mandatory = $false)]
        [string] $AIIngestionEndpoint,
        # Configuration File Path
        [Parameter(Mandatory = $false)]
        [string] $Path = 'Config.json'
    )

    if (![IO.Path]::IsPathRooted($Path)) {
        $AppDataDirectory = Join-Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ApplicationData)) 'AzureADAssessment'
        $Path = Join-Path $AppDataDirectory $Path
    }

    if ($PSBoundParameters.ContainsKey('AIDisabled')) { $script:ModuleConfig.'ai.disabled' = $AIDisabled }
    if ($PSBoundParameters.ContainsKey('AIInstrumentationKey')) { $script:ModuleConfig.'ai.instrumentationKey' = $AIInstrumentationKey }
    if ($PSBoundParameters.ContainsKey('AIIngestionEndpoint')) { $script:ModuleConfig.'ai.ingestionEndpoint' = $AIIngestionEndpoint }
    
    Assert-DirectoryExists $AppDataDirectory
    ConvertTo-Json $script:ModuleConfig | Set-Content $Path

    #return $script:ModuleConfig
}