Using the $ERROR object as an example, how would I iterate through each property, expand collections of properties, and get all values? I’d like to have the full output of an error and write it to a log file.
$ERROR|get-member shows 8 properties
$ERROR[0].CategoryInfo |Get-Member shows 5 properties
I’m assuming a recursive loop but have not been able to get it to work.
I don’t like how this is setup. You can’t tab complete to explore it. You can do:
$error | fl -force $error | select *
This is the only time I’ve ever used fl -force.
Also try Format-Custom and experiment with the depth parameter.
Thanks for the replies. I’m looking to go further, expand properties and get more details.
For exmaple - If I look at the most recent $Error, $Error[0], I see 9 properties.
PS > $Error[0].psobject.properties|Select-Object name Name ---- PSMessageDetails Exception TargetObject CategoryInfo FullyQualifiedErrorId ErrorDetails InvocationInfo ScriptStackTrace PipelineIterationInfo
One of the properties listed is “Exception”.
If I look at properties of “Exception” I see 10 more properties.
PS > $Error[0].Exception.psobject.properties|Select-Object name Name ---- ErrorRecord StackTrace WasThrownFromThrowStatement Message Data InnerException TargetSite HelpLink Source HResult
I am looking to loop through each property, and expand properties where there are more properties. Like “select-object -expand” but in a recursive loop so I can explore all properties of an object.
Thanks for the replies. I’m looking to go further, expand properties and get more details.
For example - If I look at the most recent $Error, $Error[0], I see 9 properties.
PS >; $Error[0].psobject.properties|Select-Object name Name ---- PSMessageDetails Exception TargetObject CategoryInfo FullyQualifiedErrorId ErrorDetails InvocationInfo ScriptStackTrace PipelineIterationInfo
One of the properties listed is “Exception”.
If I look at properties of “Exception” I see 10 more properties.
PS > $Error[0].Exception.psobject.properties|Select-Object name Name ---- ErrorRecord StackTrace WasThrownFromThrowStatement Message Data InnerException TargetSite HelpLink Source HResult
I am looking to loop through each property, and expand properties where there are more properties. Like “select-object -expand” but in a recursive loop so I can explore all properties of an object.
Hmm, weird things happen with get-content. Bruce Payette mentioned in the 2 hr ps arch video that get-content returned more than just text:
get-content wmi.txt | fl * -force PSPath : C:\Users\admin\wmi.txt PSParentPath : C:\Users\admin PSChildName : wmi.txt PSDrive : C PSProvider : Microsoft.PowerShell.Core\FileSystem ReadCount : 1 Length : 0