Created
April 26, 2022 14:15
-
-
Save figueroadavid/bfe02aa6e51a09b0a3f329943fb912dc to your computer and use it in GitHub Desktop.
Get HResult Error Message information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-HResultMessage { | |
| [cmdletbinding()] | |
| param( | |
| [parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [int]$HResult | |
| ) | |
| $Result = [ComponentModel.Win32Exception]::new($HResult) | |
| if ($PSVersionTable.PSVersion.Major -le 5) { | |
| @{ | |
| Data = $Result.Data | |
| ErrorCode = $Result.ErrorCode | |
| HelpLink = $Result.HelpLink | |
| HResult = $Result.HResult | |
| InnerException = $Result.InnerException | |
| Message = $Result.Message | |
| NativeErrorCode = $Result.NativeErrorCode | |
| Source = $Result.Source | |
| StackTrace = $Result.StackTrace | |
| TargetSite = $Result.TargetSite | |
| } | |
| } | |
| else { | |
| $Result | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment