PS>_ "Powershell","Automation","API's","Algorithms" -join " + "

We often come across Error codes (or Exit Codes) in windows operating system environment, but most of the timewe’re unsure what these numerical values actually mean, unless we try Googling it out the number.

WHAT IS ERROR \ EXIT CODE ?

The Exit codeor Return code or System Error code of a process in computer programming is a small number passed from a child process (or CALLEE) to a parent process (or CALLER) when it has finished executing a specific procedure or delegated task.

Windows uses 32-bit signed integers as exit codes.If a process fails initialization, a Windows system error code may be returned

So, in order to decipher these numbers, I wrote two PowerShell functions –

Import-WindowsErrorCode: To import all these error Code information from series of MSDN URL’s mention HERE

Get-WindowsErrorCodeInfo : To query the information of a specific Error Code from imported data..

PURPOSE :

Could be utilized for a better Error Handling and better Investigation and Analysis.

Like in the below screenshot I passed the exit code returned while installing a .MSI file to the function Get-WindowsErrorCodeInfo to get information like ErrorString, Description and corresponding Hexa-Decimalvalue

Similarly, more information can be queried from the Error codes generated by running .exe or .MSU files, like in below image.

IMPORTING/SAVING SYSTEM ERROR INFORMATION :

Run the below mentioned function from a Powershell console and it will make web Queries to Microsoft MSDN Web sites to capture all error codes, like in the following screenshot.

Its nothing but a series of Invoke-WebRequest’s on MSDN URL’s to web scrap the error code information, Sort them and make them in presentable format, which could be easily parsed.

Now you can either convert and Save the results locallyin a JSON file (You can also choose CSV) ,

Or, convert it to JSON, then COPY the result

and upload it to your Github Gist.

HOW TO RUN IT :

Get the script from HERE on my Github Repository and you can run the Import-WindowsErrorCode function to save the information and then Get-WindowsErrorCode to query the error codes.

Following are some ways to Query information using the Error/Exit Codes

You can query single exit codeor can pass multiple value through Pipeline.
By default it queries my Github Gist available over internet.

You can also query the exit code information from a local JSON file.

Or you can dump the JSON data on your Github Gistand retrieve the exit code information like below, by passing your URL under -GitHubJSONUrl switch

In case you don’t mention any specific exit code or path; The function will return all exit code available from my Github gist, which I would advise to be the preferable method. Which will fetch around 2700 Exit Codes

NOTE :

You can skip the importing part and directly use the Get-WindowsErrorCodeInfo function which will query my Github gist URL by default ( but Requires Internet Connectivity).

I’ve taken care of the importing part for you guys 🙂 by importing and saving the all Windows System Error codes on my public Github gist.

Updated on 21 July :

From few comments on Reddit link sharing, I’ve learned that this may not be the smartest way to get the error code description. You can also use windows Native command (Net Helpmsg Errorcode) to get the description which uses native windows API to get this information.

but after some hit and trial I’ve found that this approach has some limitations and doesn’t identifies every exit code we fetched form Microsoft websites. Like in the example in following screenshot for ERROR_INTERNET_* type error messages

I think both approaches are good and there is a trade-off between Speed and More information. Choice is yours!

Hoping you find it useful in your day to day work, comment and let me know for any improvements! Happy Learning 🙂

Skype has established its web-dependent consumer beta on the entire world, right
after starting it generally in the Usa and You.K.
earlier this month. Skype for Internet also now facilitates Linux and Chromebook for immediate online messaging communication (no voice and
video but, all those call for a plug-in installment).

The increase of your beta contributes help for a longer selection of languages to aid bolster that global user friendliness