Public/Initialize-DotsConfig.ps1

function Initialize-DotsConfig {
    <#
    .SYNOPSIS
        Initialize Dots module configuration

    .DESCRIPTION
        Initialize Dots module configuration, and $DotsConfig module variable

        This will set Dots back to the defaults, with overrides as specified by parameters

    .PARAMETER CMDBPrefix
        Prefix for Dots-owned data, when multiple data sources are present
        Defaults to Dots

        For example, a :Server might include properties with the following prefixes:
          * AD: Active Directory data e.g. ADOperatingSystem
          * PDB: PuppetDB data e.g. PDBosfamily
          * Dots: Data stored or generated by Dots e.g. DotsADUpdateDate

    .PARAMETER ScriptsPath
        Path to scripts that pull external and Dots data
        Must include scripts in respective subfolders: ExternalSources, DotsSources
        Defaults to Dots/Scripts

    .PARAMETER DataPath
        Path to yaml data where Dots is the source of truth
        Defaults to Dots/Data

    .PARAMETER ScriptOrder
        Controls order of ScriptsPath script execution
        Items not included run last
        Required in cases where data must exist first - e.g. start and end nodes for a relationship

    .PARAMETER ScriptsToRun
        Specify a whitelist of scripts that Dots will run
        All other scripts will be ignored

    .PARAMETER ScriptsToIgnore
        Specify a blacklist of scripts that Dots will ignore
        All other scripts will run

    .PARAMETER ServerUnique
        Unique identifier for a :Server. Used to correlate and to avoid duplicates
        Defaults to ${CMDBPrefix}Hostname

    .PARAMETER TestMode
        If specified, we generate Dots from pre-existing mock data

    .PARAMETER Path
        If specified, save config file to this file path
        Defaults to
          DotsConfig.xml in the user temp folder on Windows, or
          .dotsconfig in the user's home directory on Linux/macOS

    .FUNCTIONALITY
        Dots
    #>

    [cmdletbinding()]
    param(
        [string]$CMDBPrefix = 'Dots',
        [string]$DataPath = $(Join-Path $ModuleRoot 'Data'),
        [string]$ScriptsPath = $(Join-Path $ModuleRoot 'Scripts'),
        [string[]]$ScriptOrder = @( 'ADComputers',
                                  'ADUsers',
                                  'ADGroups',
                                  'PuppetDB',
                                  'Service',
                                  'Service-DependsOn' ),
        [string[]]$ScriptsToRun,
        [string[]]$ScriptsToIgnore = @('PuppetDB', 'ScheduledTask'),
        [string]$ServerUnique, # Default is computed below
        [switch]$TestMode,
        [string]$Path = $script:_DotsConfigXmlpath
    )
    if(-not $PSBoundParameters.ContainsKey('ServerUnique')) {
        $ServerUnique = "${CMDBPrefix}Hostname"
    }
    Switch ($DotsProps)
    {
        'CMDBPrefix'      { $Script:DotsConfig.CMDBPrefix = $CMDBPrefix }
        'DataPath'        { $Script:DotsConfig.DataPath = $DataPath }
        'ScriptsPath'     { $Script:DotsConfig.ScriptsPath = $ScriptsPath }
        'ScriptOrder'     { $Script:DotsConfig.ScriptOrder = [string[]]$ScriptOrder }
        'ScriptsToRun'    { $Script:DotsConfig.ScriptsToRun = [string[]]$ScriptsToRun }
        'ScriptsToIgnore' { $Script:DotsConfig.ScriptsToIgnore = [string[]]$ScriptsToIgnore }
        'ServerUnique'    { $Script:DotsConfig.ServerUnique = $ServerUnique }
        'TestMode'        { $Script:DotsConfig.TestMode = [bool]$TestMode }
    }

    # Create variables for config props, for convenience
    foreach($Prop in $DotsProps) {
        Set-Variable -Name $Prop -Value $DotsConfig.$Prop -Scope Script -Force
    }

    $SelectParams = @{
        Property = $Script:DotsProps
    }
    if(-not (Test-IsWindows)) {
        $SelectParams.Add('ExcludeProperty', 'Credential')
    }
    #Write the global variable and the xml
    $Script:DotsConfig |
        Select-Object @SelectParams |
        Export-Clixml -Path $Path -Force
}