Reputation: 306
Get-Error should be one of the basic PS commands, but it doesn't work for me. I get an error:
get-error : The term 'get-error' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I updated the module Microsoft.PowerShell.Utility. I've checked the list of commands in it with:
Get-Command -Module Microsoft.PowerShell.Utility
And it is still not there.
Does anyone know how to fix it or how to get detailed error info without it?
Thanks!
Upvotes: 2
Views: 6513
Reputation: 10799
Powershell errors are objects, just like everything else. As such, you can interrogate their properties and invoke their methods. They’re documented on MSDocs as System.Management.Automation.ErrorRecord.
When I forced an error, and looked at the object with Get-Member
, I saw
PS D:\Scripts> $error[0] | Get-Member
TypeName: System.Management.Automation.ErrorRecord
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System....
GetType Method type GetType()
ToString Method string ToString()
CategoryInfo Property System.Management.Automation.ErrorCategoryInfo CategoryInfo {get;}
ErrorDetails Property System.Management.Automation.ErrorDetails ErrorDetails {get;set;}
Exception Property System.Exception Exception {get;}
FullyQualifiedErrorId Property string FullyQualifiedErrorId {get;}
InvocationInfo Property System.Management.Automation.InvocationInfo InvocationInfo {get;}
PipelineIterationInfo Property System.Collections.ObjectModel.ReadOnlyCollection[int] PipelineIterationInfo {g...
ScriptStackTrace Property string ScriptStackTrace {get;}
TargetObject Property System.Object TargetObject {get;}
PSMessageDetails ScriptProperty System.Object PSMessageDetails {get=& { Set-StrictMode -Version 1; $this.Except...
PS D:\Scripts>
but using the MSDocs will give you more useful information.
Upvotes: 1