private/skipSettings.psm1

<#
    .SYNOPSIS
        Merge-SkippedRule adds the SkipRule Node to the XML and moves specified rules to the SkipRule Node.
 
    .PARAMETER StigContent
        The STIG XML data to be manipulated
 
    .PARAMETER SkippedRule
        An array of one or more rules to be added to the SkipRule Node.
 
    .EXAMPLE
        Merge-SkippedRule -StigContent <StigData.xml> -SkippedRule @("V-15505", "V-15506")
#>

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

        [Parameter(Mandatory = $true)]
        [PsObject]
        $skippedRule
    )

    # This creates a Skip rule XML element and appends it to $stigContent
    [System.XML.XMLElement] $SkipNode = $stigContent.Value.CreateElement("SkipRule")
    [void] $stigContent.Value.DISASTIG.AppendChild($SkipNode)
    
    Foreach ($Rule in $skippedRule)
    {
        # Lookup the STIG Id in the data
        $ruleToOverride = ( $stigContent.value.DISASTIG | Select-Xml -XPath "//Rule[@id='$( $Rule )']" -ErrorAction Stop ).Node
        [void] $stigContent.Value.SelectSingleNode("//SkipRule").AppendChild($RuleToOverride)
    
        # If an Id is not found we can continue, but notify the user.
        if ($null -eq $ruleToOverride)
        {
            Write-warning "$($Rule) was not found"
            continue
        }
        
        # Append [Skip] to the STIG title
        $ruleToOverride.title = "[Skip]" + $ruleToOverride.title
    }
}

<#
    .SYNOPSIS
        Merge-SkippedRuleType Changes the rule type of specified rules to SkipRule Node.
 
    .DESCRIPTION
        Merge-SkippedRuleType doesn't move any of the rules. in this function. It obtaines the Id's of all the rules of a certain type and passes
        those as an array to Merge-StigRule.
 
    .PARAMETER StigContent
        The STIG XML data to be manipulated
 
    .PARAMETER SkippedRuleType
        An array of one or more rule types to be added to the SkipRule Node.
 
    .EXAMPLE
        Merge-SkippedRuleType -StigContent <StigData.xml> -SkippedRuleType "AuditPolicyRule"
#>


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

        [Parameter(Mandatory = $true)]
        [PsObject]
        $skippedRuleType
    )

    foreach ($RuleType in $skippedRuleType)
    {
        #Collects the Id's of the rules of the RuleType
        $ruleToOverride = $stigContent.Value.DISASTIG.$RuleType.rule.id

        # If an Id is not found we can continue, but notify the user.
        if ($null -eq $ruleToOverride)
        {
            Write-warning "$($Rule) was not found"
            continue
        }
        else
        {
            Merge-SkippedRule -stigContent $stigContent -skippedRule $ruleToOverride
        }
    }
}