When I take my custom object and pipe it to format-table, everything looks good - except for the diskInfo. I would love it if it had like a table in a table so that I could see it when I run this.
Is there a way to either set this up properly with the objects or output it to the screen??
You’re constructing the object properly, but PowerShell’s built-in formatting system can’t handle object hierarchies in a “table in a table.” If you pipe your output to Format-Custom, you’ll see that it SEES the hierarchy, but Format-Table just can’t do anything with it (nor could Format-List). Your only native solution would be to create your own custom format in a .format.ps1xml file, designed to handle the output of your command specifically. That’s a pretty advanced topic, as I don’t think the custom formats are actually documented in any real detail anyplace.
You can get pretty close to what you are after without mucking around with any .format.ps1xml file stuff. Here’s a script I put together to do this, and the output format is almost perfect for what you are looking for:
The magic is in the ToString method definition for the custom My.DiskInfo objects. That controls how those objects are resolved to string when you view the contents of the containing collection in your list of parent objects.
You could also create a “display” property that shows the diskinfo as a nested table (maybe call it DiskTable), and have it contain the nested table as a string for easy reading.