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 empty IncludeDotsScripts $True effectively adds the Dots module Dots/Scripts path to this .PARAMETER IncludeDotsScripts Whether to include Dots/Scripts in functions that use ScriptsPath Defaults to $true .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 AllLower If specified, attempt to convert all string properties to lowercase before loading into Neo4j Defaults to $True .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 = $null, [bool]$IncludeDotsScripts = $true, [string[]]$ScriptOrder = @( 'ADComputers', 'ADUsers', 'ADGroups', 'PuppetDB', 'Service', 'Service-DependsOn' ), [string[]]$ScriptsToRun, [string[]]$ScriptsToIgnore = @('PuppetDB', 'ScheduledTask'), [string]$ServerUnique, # Default is computed below [switch]$TestMode, [bool]$AllLower = $true, [string]$Path = $script:_DotsConfigXmlpath ) if(-not $PSBoundParameters.ContainsKey('ServerUnique')) { $ServerUnique = "${CMDBPrefix}Hostname" } Switch ($DotsProps) { 'CMDBPrefix' { $Script:DotsConfig.CMDBPrefix = $CMDBPrefix } 'DataPath' { $Script:DotsConfig.DataPath = [string[]]$DataPath } 'ScriptsPath' { $Script:DotsConfig.ScriptsPath = [string[]]$ScriptsPath } 'IncludeDotsScripts' { $Script:DotsConfig.IncludeDotsScripts = $IncludeDotsScripts } '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 } 'AllLower' { $Script:DotsConfig.AllLower = $AllLower } } # 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 } |