functions/public/Confirm-ValidConfigStore.ps1

function Confirm-ValidConfigStore {
    [CmdletBinding()]
    param (
        [string] $ConfigStorePath,
        [string] $ConfigManifestPath
    )
    begin {
        function ConvertFrom-ConfigXmlToObject {
            [CmdletBinding()]
            param (
                [Parameter(Position = 0, Mandatory = $true)]
                [xml]$Xml
            )
            $variables = @()
            foreach ($scopeNode in $xml.installation.settings.scope) {
                foreach ($variableNode in $scopeNode.variable) {
                    $variable = New-Object PSObject
                    $variable | Add-Member -Type NoteProperty -Name scope_variable -Value "$($scopeNode.name).$($variableNode.name)"
                    $variable | Add-Member -Type NoteProperty -Name scope -Value ($scopeNode.name)
                    $variable | Add-Member -Type NoteProperty -Name variable -Value ($variableNode.name)
                    $variable | Add-Member -Type NoteProperty -Name value -Value ($variableNode.value)
                    $variables += $variable
                }
            }
            return $variables
        }
        function Write-XmlToScreen {
            [CmdletBinding()]
            param (
                [xml]$xml
            )
            $StringWriter = New-Object System.IO.StringWriter;
            $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
            $XmlWriter.Formatting = "indented";
            $xml.WriteTo($XmlWriter);
            $XmlWriter.Flush();
            $StringWriter.Flush();
            Write-Output $StringWriter.ToString();
        }
    }
    process {
        $configXml = [xml](Get-Content $ConfigStorePath)
        $manifestXml = [xml](Get-Content $ConfigManifestPath)
        $configVariables = ConvertFrom-ConfigXmlToObject $configXml
        $manifestVariables = ConvertFrom-ConfigXmlToObject $manifestXml

        $missingVariables = @()
        foreach ($manifestVariable in $manifestVariables) {
            if ($configVariables.scope_variable -notcontains $manifestVariable.scope_variable) {
                $missingVariables += $manifestVariable
            }
        }
        if ($missingVariables) {
            $missingScopes = $missingVariables | Group-Object scope

            $text = @"
MISSING CONFIGURATIONS REPORT
Manifest: $($ConfigManifestPath)
Generated: $(Get-Date)
 
After doing a comparison of the configuration manifest with the install.config store
it appears that there are some missing configurations that need to be added to this
computers install.config store before there can be a successful installation.
 
Below are the missing variables with template/default values that are to be only used
as a guide. Please review the values carefully to ensure they are correct and then
copy and paste them to the install.config file.
 
COPY TO LOCATION: $($ConfigStorePath)
"@

    
            [xml]$doc = New-Object System.Xml.XmlDocument
            $doc.AppendChild($doc.CreateComment($text)) | Out-Null
            $installation = $doc.CreateElement("installation")
            $settings = $doc.CreateElement("settings")

            foreach ($missingScope in $missingScopes) {
                $scope = $doc.CreateElement("scope")
                $scope.SetAttribute("name", $missingScope.Name)
        
                foreach ($missingVariable in $missingScope.Group) {
                    $variable = $doc.CreateElement("variable")
                    $variable.SetAttribute("name", $missingVariable.variable)
                    $variable.SetAttribute("value", $missingVariable.value)
                    $scope.AppendChild($variable) | Out-Null
                }
                $settings.AppendChild($scope) | Out-Null
            }
        
            $installation.AppendChild($settings) | Out-Null
            $doc.AppendChild($installation) | Out-Null            

            Write-DosMessage -Level "Fatal" -Message "$(Write-XmlToScreen $doc)"
        }    
        Write-DosMessage -Level "Information" -Message "All required configurations found in the install.config"
    }
}