Dots.psm1

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
#Get public and private function definition files.
$Public  = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
$ModuleRoot = $PSScriptRoot

#Dot source the files
Foreach($import in @($Public + $Private)) {
    try {
        . $import.fullname
    }
    catch {
        Write-Error -Message "Failed to import function $($import.fullname): $_"
    }
}

$DotsProps = 'CMDBPrefix',
             'ScriptsPath',
             'DataPath',
             'IncludeDotsScripts',
             'ScriptOrder',
             'ScriptsToRun',
             'ScriptsToIgnore',
             'ServerUnique',
             'TestMode',
             'AllLower'
$DotsConfig = [pscustomobject]@{} | Select-Object $DotsProps
$_DotsConfigXmlpath = Get-DotsConfigPath
if(-not (Test-Path -Path $_DotsConfigXmlpath -ErrorAction SilentlyContinue)) {
    try {
        Write-Warning "Did not find config file [$_DotsConfigXmlpath], attempting to initialize"
        Initialize-DotsConfig -Path $_DotsConfigXmlpath -ErrorAction Stop
    }
    catch {
        Write-Warning "Failed to create config file [$_DotsConfigXmlpath]: $_"
    }
}
else {
    $DotsConfig = Get-DotsConfig -Source Xml
}

# Create variables for config props, for convenience
# We also do this in Set/Initialize commands
foreach($Prop in $DotsProps) {
    Set-Variable -Name $Prop -Value $DotsConfig.$Prop -Force
}

Export-ModuleMember -Function $Public.Basename