< Back

Get-Win32ErrorMessage

Sat Jan 18, 2020 6:50 pm

NAME Get-Win32ErrorMessage



SYNOPSIS

Gets the Win32 Error message.





SYNTAX

Get-Win32ErrorMessage [-ErrorCode] <Int32> [<CommonParameters>]





DESCRIPTION

Gets the Win32 Error message based on error code passed in





PARAMETERS

-ErrorCode <Int32>

The error code to convert. \\When calling a PInvoke function this can be retrieved with

[System.Runtime.InteropServices.Marshal]::GetLastWin32Error()



This should be done inline, e.g.

[PInvoke]::Function(); $err_code = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()



Failure to do this in line may result in the wrong error code being retrieved.



Required? true

Position? 1

Default value 0

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

System.String. The Win32 error message for the code specified.





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$res = [PInvoke]::CreatePipe(



[Ref]$ReadHandle,

[Ref]$WriteHandle,

0,

0

); $err_code = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()



if (-not $res) {

$msg = Get-Win32ErrorMessage -ErrorCode $err_code

throw $msg

}











RELATED LINKS