Select with object hashtable

Hello All,

My script $vm = get-vm | ft Name, numcpu, memorygb, @{N=“Hard Disk”; E={get-harddisk -VM $_ |
`select -ExpandProperty CapacityGB }} , @{N=“IP Address”;E={@($_.guest.IPAddress[0])}} -AutoSize

Give me all vms with hdd sizes of them. But if any vm have more than a few disks results looks like

{100, 1536, 1224, 1024…}

What should I change in script to show all available disk ?

Is it possible to show disks without brackets { } ?

 

Regards

Marek

 

 

 

 

 

Put format-table last. It turns everything into format objects for screen text output.

[pscustomobject]@{name='joe'} | format-table | % gettype 

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
False    False    FormatStartData                          Microsoft.PowerShell.Commands.Internal.Format.StartData
False    False    GroupStartData                           Microsoft.PowerShell.Commands.Internal.Format.StartData
False    False    FormatEntryData                          Microsoft.PowerShell.Commands.Internal.Format.PacketInfoData
False    False    GroupEndData                             Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData
False    False    FormatEndData                            Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData

I don’t understand. Added here

get-vm | ft Name, numcpu, memorygb, @{N=“Hard Disk”; E={get-harddisk -VM $_ |

select -ExpandProperty CapacityGB <strong>| FT</strong> }} , @{N="IP Address";E={@($_.guest.IPAddress[0])}}

but instand of hdd size it shows type "{Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData.."
I also checked FT in last section
get-vm | ft Name, numcpu, memorygb, @{N="Hard Disk"; E={get-harddisk -VM $_ |

select -ExpandProperty CapacityGB }} , @{N=“IP Address”;E={@($_.guest.IPAddress[0])}} | FT

but results is still {100, 1536, 1224, 1024…}

 

I don’t understand your code. It’s is convoluted. Please format it with the pre tags and include the output. I don’t have the get-vm command, so I’m also at a disadvantage. Maybe you can turn the array into a string like this.

(1,2,3) -join ', '

1, 2, 3
$vm = get-vm | 
    ft Name, numcpu, memorygb, 
        @{N=”Hard Disk”; E={ (get-harddisk -VM $_ |  select -ExpandProperty CapacityGB) -join ',' }} , 
        @{N=”IP Address”;E={ $_.guest.IPAddress[0] }} -AutoSize