I needed to create a custom output formatter that would work for any object. Since I need it to work with any object, that means I won’t know before hand what properties the object has, or which of those properties I want to actually output. So, I couldn’t use any of the existing PowerShell format cmdlets like format-table, format-list, or format-custom. Instead, I needed to look at each object, get a list of its properties and their associated value(s), and then loop through those and display them with my custom formatter. Here’s what I did:
Thats it. The first line gets all the “Property” members of the object ($obj), and puts the “Name” of each property into an array called $propnames. Line 2 gets the value(s) associated with that property name and puts that result into another array called $propvals. Then I can pass each name/value pair to my write-custom function, which does the custom output work.
Technorati Tags:
PowerShell