internal/functions/update-activevariables.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

<#
    .SYNOPSIS
        Update all the active variables
         
    .DESCRIPTION
        All PSF configuration entries that are names *.active* will be extracted to their corresponding $script:VARIABLENAMe
         
    .EXAMPLE
        PS C:\> Update-ActiveVariables
         
        This will update all the variables that maps directly to a PSF configuration value in the *.active* part of the configuration store.
         
    .NOTES
        Author: Mötz Jensen (@Splaxi)
#>

function Update-ActiveVariables {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
    [CmdletBinding()]
    param ()
    
    foreach ($item in (Get-PSFConfig -FullName ax2012.tools.active*)) {
        $nameTemp = $item.FullName -replace "^ax2012.tools.", ""
        $name = ($nameTemp -Split "\." | ForEach-Object { (Get-Culture).TextInfo.ToTitleCase($_) } ) -Join ""
        
        New-Variable -Name $name -Value $item.Value -Scope Script -Force
    }
    
    if ([System.String]::IsNullOrEmpty(($Script:ActiveAosDatabaseserver -replace "null", "" ))) {
        Write-PSFMessage -Level Verbose -Message "ActiveAosDatabaseserver was empty. Defaulting to `"localhost`""
        $Script:ActiveAosDatabaseserver = "localhost"
    }
    
    if ([System.String]::IsNullOrEmpty(($Script:ActiveAosModelstoredatabase -replace "null", "" ))) {
        Write-PSFMessage -Level Verbose -Message "ActiveAosModelstoredatabase was empty. Defaulting to `"MicrosoftDynamicsAx_model`""
        $Script:ActiveAosModelstoredatabase = "MicrosoftDynamicsAx_model"
    }
    
    if ([System.String]::IsNullOrEmpty(($Script:ActiveAosDatabase -replace "null", "" ))) {
        Write-PSFMessage -Level Verbose -Message "ActiveAosDatabase was empty. Defaulting to `"MicrosoftDynamicsAx`""
        $Script:ActiveAosDatabase = "MicrosoftDynamicsAx"
    }
}