Skip to content

Commit

Permalink
Add a helper function for formatting Win32 error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
itm4n committed Dec 30, 2024
1 parent a39a424 commit 307c183
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/helper/Utility.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function Format-Error {

[OutputType([String])]
[CmdletBinding()]
param (
[Parameter(Position=0, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[Int32] $Code
)

process {
$ErrorObject = [ComponentModel.Win32Exception] $Code
$ErrorMessage = "$($ErrorObject.Message)"
if ($ErrorObject.NativeErrorCode -ge 0) { $ErrorMessage += " ($($ErrorObject.NativeErrorCode))" }
$ErrorMessage += " - HRESULT: $('0x{0:x8}' -f $ErrorObject.HResult)"
return $ErrorMessage
}
}

function Get-InitialSessionState {

[OutputType([Management.Automation.Runspaces.InitialSessionState])]
Expand Down

0 comments on commit 307c183

Please sign in to comment.