functions/Import-PowerShellDataFileConfigs.ps1

<#
.SYNOPSIS
    This function loads config hash tables from definitions and merges them into one.
.DESCRIPTION
    This function accepts two paths, each required to point to config definitions, loads them
    each into separate has tables and them merges these tables into a single configuration table.
.PARAMETER BaseConfigPath
    Path to base config file which defines a hash table of configuration items.
.PARAMETER EnvironmentConfigPath
    Path to environment config file which defines a hash table of configuration items.
.EXAMPLE 1
    PS C:\> $basePath = "$PSScriptRoot\Environments\Config.Base.psd1"
    PS C:\> $envPath = "$PSScriptRoot\Environments\Config.Env.$EnvironmentName.psd1"
    PS C:\> $config = Merge-PowerShellDataFileConfigs -BaseConfigPath $basePath -EnvironmentConfigPath $envPath
     
    This example loades the two specified config tables from their definitions and merges them into one.
#>

function Import-PowerShellDataFileConfigs {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$True)] 
        [string] 
        $BaseConfigPath,
        [Parameter(Mandatory=$True)] 
        [string] 
        $EnvironmentConfigPath
    )
    
    begin {
        Write-Information "Begin importing powershell data file configs"
        $mergedConfiguration = @{}
    }
    
    process {
        $baseConfig = Import-PowerShellDataFile -Path $BaseConfigPath
        $environmentConfig = Import-PowerShellDataFile -Path $EnvironmentConfigPath
    
        $mergedConfiguration = $baseConfig, $environmentConfig | Merge-ConfigHashtables
    }
    
    end {
        Write-Information "End importing powershell data file configs"
        $mergedConfiguration
    }
}