Return codes from WBBackup in Powershell 7.x

Shane King 71 Reputation points
2023-10-03T22:28:44.2166667+00:00

The return code provided by PS Get-WBJob after running WBBackup for the property HResult are not documented anywhere. Is there a reference for all codes. With none documented, we basically have to wait for all to occurr before script can be written to respond.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,823 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ian Xue-MSFT 41,711 Reputation points Microsoft External Staff
    2023-10-09T03:52:45.0766667+00:00

    Hi,

    The top bit indicates if success or failure. The 16-26 bits are the facility and the 0-15 bits are the error code. The details of the facility and the error code can be found here.

    https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes

    https://learn.microsoft.com/en-us/archive/blogs/andrew_richards/hresult-facility-by-value

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Rich Matheisen 47,786 Reputation points
    2023-10-09T19:51:59.1033333+00:00

    Here's an example of how to pull apart the HRESULT without using -BAND (and having to reverse bit counts and shift results).

    As for a complete list of Windows error coded, there are thousands of them (probably tens of thousands!). If you want to build your own (SMALL!) subset of error to use in your code, use the Windows Error tool: https://learn.microsoft.com/en-us/windows/win32/debug/system-error-code-lookup-tool

    # reference https://en.wikipedia.org/wiki/HRESULT
    
    #   3 3 2 2 2  2 2 2 2 2 2 2 1 1 1 1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0   MEMORY 
    #   1 0 9 8 7  6 5 4 3 2 1 0 9 8 7 6  5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
    
    #   S R C N X     ----- Facility ---  ----------- Code --------------   FIELDS
    #   1 0 0 0 0  0 0 0 0 0 0 0 0 1 1 1  0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1   0x80070005 (example)
    #
    #   0 0 0 0 0  0 0 0 0 0 1 1 1 1 1 1  1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3     INDEX
    #   0 1 2 3 4  5 6 7 8 9 0 1 2 3 4 5  6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    
    [int32]$HRESULT = 0x80070005
    [string]$a = [convert]::ToString($HRESULT,2)
    
    $facility = [Convert]::ToInt32( ($a[5..15] -join "") , 2)
    $code =     [Convert]::ToInt32( ($a[16..31] -join ""), 2)
    
    "0x{0:X2}" -f $facility   # in hexadecimal
    "0x{0:X8}" -f $code       # in hexadecimal
    
    # system error codes (LOTS of them!) here: https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.