I wanted to achieve the same thing without using the winrm.vbs file as vbscript isn’t allowed in my environment.
I opened the winrm vbscript and looked how the error code is translated.
The string is first converted to hexadecimal and then to a long integer.
Finally it uses a COM object to translate the error to a human readable error description.
I remembered that I’ve already worked on this hexadecimal to long integer conversion.
I first tried Boe’s approach but it failed 😦
Then I looked at this WSMan.Automation COMObject methods:
So I used my Get-ErrorCode function (available on this page) and got the expected result 🙂
(New-Object -ComObject WSMAN.Automation).GetErrorMessage( (Get-ErrorCode 0x80338104).Int64)