Public/Enable-HPRFGlobalBypass.ps1

Function Enable-HPRFGlobalBypass {
    <#
        .SYNOPSIS
            Enables global registry bypass the next time the system is restarted, or when UpdateGlobalBypass is called.
        .DESCRIPTION
            Enables global registry bypass the next time the system is restarted, or when UpdateGlobalBypass is called.
        .INPUTS
            None
        .OUTPUTS
            Returns 0 when successful. Otherwise, it returns an error code.
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
        .LINK
            http://h10032.www1.hp.com/ctg/Manual/c06173592
    #>

    [CmdletBinding(
        SupportsShouldProcess = $True,
        ConfirmImpact = "Medium"
    )]
    Param ()
    Begin { }
    Process {
        If ($null -ne $HpRF) {
            If ($PSCmdlet.ShouldProcess("Enable global registry bypass")) {
                $Ret = $HpRF.EnableGlobalBypass()
                If ($Ret.ReturnValue -gt 0) {
                    Throw "Enabling global bypass for registry failed with error $Ret.ReturnValue"
                } Else {
                    Write-Verbose "Enabling global bypass for registry succeeded!"
                    # Be sure properties are set correctly
                    $GlobalBypassFlag = [PSCustomobject]@{
                        "Enabled flag"     = $HpRF.GlobalBypassEnabled
                        "NextEnabled flag" = $HpRF.GlobalBypassNextEnabled
                    }
                    $GlobalBypassFlag.PSObject.TypeNames.Insert(0, 'HPWriteManager.GlobalBypass.Mode')
                    $GlobalBypassFlags += $GlobalBypassFlag

                    if (!$HpRF.GlobalBypassNextEnabled) {
                        Write-Warning "Global bypass will be disabled in next session"
                    }
                }
            }
        }
    }
    End {
        If ($GlobalBypassFlags) {
            Return $GlobalBypassFlags
        }
    }
}