I have a collection of Objects with NoteProperties. One of these properties is an array. I would like to have an easy way to display the members of this noteproperty not just '[System.Object]' when I use ConvertTo-HTML.
For example, I have a property called "Computername" and one called "Disks" that is actually an array of all Disks of that computer. The output of ConvertTo-HTML looks like this:
Computername Disks
fs System.Object[]
dc1 System.Object[]
Is there an easy way to display the members of "Disks" without manually creating the html-output?
Edit:
One Disk-object has actually 3 values (name, capacity and free space) that have to be shown too.
The output of $collection[0].Disks on the powershell prompt could look like this (depending on the disks-count and so on):
PS > $collection[0].Disks
Bezeichnung Kapazität (MB) Freier Speicher (MB)
----------- -------------- --------------------
C:\ 40963 23040 (56 %)
D:\ 184324 39024 (21 %)
E:\ 204805 103373 (50 %)
I was thinking about something like a tree that shows the computername first and then a table of all disks of that computer. Something like (could be more beautiful ;)):
Computername
fs
Bezeichnung Kapazität (MB) Freier Speicher (MB)
----------- -------------- --------------------
C:\ 40963 23040 (56 %)
D:\ 184324 39024 (21 %)
E:\ 204805 103373 (50 %)
dc1
My normal approach in these kinds of cases is to expand the data into a more table-friendly format, rather than spend a lot of time customizing the HTML.
$collection |
select ComputerName -ExpandProperty Disks |
ConvertTo-Html -Fragment -Property ComputerName,Name,Capacity,'Free Space'
This expands the list of disks for each computer, so that each appears in a separate row in the table along side the computer name.
ComputerName Name Capacity Free Space
------------ ---- -------- ----------
fs C:\ 109324 60986
fs D:\ 289313 281692
dc1 C:\ 290473 12626
dc1 D:\ 283195 125983
dc1 E:\ 105652 13898
You can convert them into a string beforehand:
Get-Foo | foreach { $_.Disks = $_.Disks -join ', ' } | ConvertTo-HTML
or maybe without actually changing your objects:
Get-Foo | select Computername,@{L=Disks;E={$_.Disks -join ', '}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With