3

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 

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

Comments

2

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 ', '}}

2 Comments

Thanks for your suggestion. I'm sorry I forgot to tell that there are 3 (or more in the future) values per disk that I want to show. I thought of something similar than a tree to show the Computername first and then a table of all disks under it.
I think in that case you need more than a single ConvertTo-HTML. I don't think you can do this without building some HTML yourself. You can still create the disk tables with ConvertTo-HTML, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.