private/organizationSettings.psm1

<#
    .SYNOPSIS
    Looks up the matching organizationalSettings file if one is not provided and and merges the
    data into the referenced StigData
 
    .PARAMETER stigContent
    A reference to the STIG content that is being processed
 
    .PARAMETER stigContentPath
     
 
    .PARAMETER OrganizationalSettingsPath
    The path to the customer provided organizational settings file that contains the values to
    define a specifc value within an allowable range.
 
    .EXAMPLE
    An example
 
    .NOTES
    General notes
#>

function Merge-OrganizationSettingsFile
{
    [outputtype([void])]
    [cmdletbinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [ref] 
        $stigContent,

        [Parameter(Mandatory = $true)]
        [string] 
        $stigContentPath,

        [Parameter()]
        [string] 
        $OrganizationalSettingsPath
    )

    $ruleTypeToProperty = Import-PowerShellDataFile -Path $PSScriptRoot\stigTypes.psd1

    $OrgSettingPath = $stigContentPath -replace "\.xml", ".org.default.xml"
    # Get the org settings file
    [xml] $orgSettings = Get-Content -Path $OrgSettingPath -Raw

    # Merge the localsettings.xml file into the base stig
    foreach ( $node in $stigContent.value.DISASTIG.ChildNodes.Name )
    {
        # Get the list of STIG settings for the current type
        foreach ( $rule in $stigContent.value.DISASTIG.$node.Rule )
        {
            if ( $rule.OrganizationValueRequired -eq $true )
            {
                $orgSetting = $orgSettings | 
                    Select-Xml -XPath "//OrganizationalSetting[@id='$( $rule.id )']"
                
                if ( $null -eq $orgSetting )
                {
                    throw "An organizational setting was not found for $( $rule.id )."
                }

                if ( -not ( & ( [Scriptblock]::Create( "$($rule.OrganizationValueTestString)" -f $orgSetting.node.value.ToString() ) ) ) )
                {
                    throw "The local setting ($($orgSetting.node.value.ToString())) for $($rule.id) is not within the specified range ($($rule.OrganizationValueTestString))
                    Please update $OrgSettingPath"

                }

                $propertyToOverride = $ruleTypeToProperty.$node
                $rule.$propertyToOverride = $orgSetting.node.value.ToString()
            }
        }
    }
}