Public/Get-UWFWindowsUpdate.ps1

Function Get-UWFWindowsUpdate {
    <#
    .SYNOPSIS
        Calls Windows Update to download and install critical and security updates for your device running Windows 10 Enterprise.
    .DESCRIPTION
        Calls Windows Update to download and install critical and security updates for your device running Windows 10 Enterprise.
    .INPUTS
        None
    .OUTPUTS
        Returns 0 on succes, 3010 on restart required and any other value on a generic error.
        Returns an HRESULT value that indicates WMI status or a WMI error.
    .EXAMPLE
        Get-UWFWindowsUpdate
    .LINK
        about_functions_advanced
    .LINK
        about_CommonParameters
    #>

    [CmdletBinding(
        ConfirmImpact = "Medium"
    )]
    Param()

    Begin {
        If (-not $PSBoundParameters.ContainsKey('Verbose')) {
            $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference')
        }
        If (-not $PSBoundParameters.ContainsKey('WhatIf')) {
            $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference')
        }
        If (-not $PSBoundParameters.ContainsKey('Confirm')) {
            $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference')
        }
        If (-not $PSBoundParameters.ContainsKey('ErrorAction')) {
            $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference')
        }
    }

    Process {
        If (!$Script:UWFServicing) {
            $ExitCode = 424
            Throw "Unable to get handle to an instance of the UWF_Servicing class"
        }
        $UpdateWindows = $Script:UWFServicing.UpdateWindows()
        $ExitCode = $UpdateWindows.UpdateStatus
    }

    End {
        If ($Null -eq $ExitCode) {
            # 424 Failed Dependency
            $ExitCode = 424
        }
        Return $("{0:x0}" -f $ExitCode)
    }
}