Public/Add-HPRFExclusion.ps1

Function Add-HPRFExclusion {
    <#
        .SYNOPSIS
            Adds a key (and all values/subkeys of that key) to the key exclusion list.
            The path must be a path beginning with a well-known key (e.g. HKLM\\System\\CurrentControlSet\\Services or HKU\\.DEFAULT).
        .DESCRIPTION
            Adds a key (and all values/subkeys of that key) to the key exclusion list.
            The path must be a path beginning with a well-known key (e.g. HKLM\\System\\CurrentControlSet\\Services or HKU\\.DEFAULT).
        .PARAMETER ExclusionKey
            The registry key to exclude
        .INPUTS
            System.String
        .EXAMPLE
            Add-HPRFExclusion -ExclusionKey HKLM\\System\\CurrentControlSet\\Services
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
        .LINK
            http://h10032.www1.hp.com/ctg/Manual/c06173592
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true,
        ConfirmImpact = "Medium"
    )]
    [OutputType('System.String')]
    Param(
        [Parameter(Mandatory = $true)]
        [String]$ExclusionKey
    )
    Begin { }
    Process {
        If ($null -ne $HpRF) {
            If ($PSCmdlet.ShouldProcess($ExclusionKey, "Add to exclusion list")) {
                $Ret = $HpRF.AddExclusion($ExclusionKey)
                If ($Ret.ReturnValue -gt 0) {
                    Throw "Exclusion key $ExclusionKey was NOT added. Error: $Ret.ReturnValue"
                } Else {
                    Write-Verbose "Exclusion key $ExclusionKey added successfully."
                    # Be sure properties are set correctly
                    If ($null -ne $HPRFEE) {
                        Write-Output "Active Key Exclusions"
                        Foreach ($Item in $HPRFEE) {
                            If ($Item.Active) {
                                Write-Output "Excluded Key: " $Item.KeyName
                            }
                        }
                        write-Output "Key Exclusions in Next Session"
                        ForEach ($Item in $HPRFEE) {
                            If ($Item.NextActive) {
                                write-Output "Excluded Key: " $Item.KeyName
                            }
                        }
                    }
                }
            }
        }
    }
    End {

    }
}