Public/Disable-HPRFGlobalBypass.ps1

Function Disable-HPRFGlobalBypass {
    <#
        .SYNOPSIS
            Disables registry bypass the next time the system is restarted, or when UpdateGlobalBypass is called.
        .DESCRIPTION
            Disables 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("Disable Global Bypass")) {
                $Ret = $HpRF.DisableGlobalBypass()
                If ($Ret.ReturnValue -gt 0) {
                    Throw "Disabling global bypass for registry failed with error $Ret.ReturnValue"
                } Else {
                    Write-Verbose "Disabling 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
        }
    }
}