Public/Update-HPRFGlobalBypass.ps1

Function Update-HPRFGlobalBypass {
    <#
        .SYNOPSIS
            Causes Global Bypass to be immediately enabled or disabled, based on GlobalBypassNextEnabled.
        .DESCRIPTION
            Causes Global Bypass to be immediately enabled or disabled, based on GlobalBypassNextEnabled.
        .INPUTS
            None
        .LINK
            about_functions_advanced
        .LINK
            about_CommonParameters
        .LINK
            http://h10032.www1.hp.com/ctg/Manual/c06173592
    #>

    [CmdletBinding(
        SupportsShouldProcess = $true,
        ConfirmImpact = "Medium"
    )]
    [OutputType('HPWriteManager.GlobalBypass.Mode')]
    Param()
    Begin { }
    Process {
        If ($null -ne $HpRF) {
            If ($PSCmdlet.ShouldProcess("Global registry bypass", "Update")) {
                $Ret = $HpRF.UpdateGlobalBypass()
                If ($Ret.ReturnValue -gt 0) {
                    Throw "Global bypass state for registry failed to be updated with error $Ret.ReturnValue"
                } Else {
                    Write-Output "Global bypass for registry has been updated!"
                    # Be sure properties are set correctly
                    $GlobalBypass = [PSCustomObject]@{
                        "Enabled Flag"     = $HPRF.GlobalBypassEnabled
                        "NextEnabled Flag" = $HPRF.GlobalBypassNextEnabled
                    }
                    $GlobalBypass.PSObject.TypeNames.Insert(0, 'HPWriteManager.GlobalBypass.Mode')
                }
            }
        }
    }
    End {
        If ($HPRF.GlobalBypassNextEnabled) {
            Write-Warning "Global bypass will be enabled in next session"
        }
        If ($GlobalBypass) {
            Return $GlobalBypass
        }
    }
}