- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
get-vm cbslnpcs1 | get-harddisk | select VM, CapacityGB
VM CapacityGB
-- ----------
?? 60
?? 40
?? 20
Why don't i see the VM server Name? is it because Select VM is in third pipe and the query is harddisk and harddisk does not have a vm attribute associated with it? How do i get the third section (Select VM) to get-VM first section to report VM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are right. The output of Get-Harddisk does not have a VM property. In this case, you can use the Parent property that contains the VM. For example,
Get-VM | Get-HardDisk | Select Parent,CapacityGB
A more general solution is to use the -PipelineVariable parameter with the Get-VM cmdlet to save the current VM in a variable. Then you can use a calculated property to display the VM name, as follows:
Get-VM -PipelineVariable VM | Get-HardDisk | Select @{Name='VM';Expression={$VM.Name}},CapacityGB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To return the name of the virtual machine name associated with the virtual machine hard disk from the Get-HardDisk cmdlet output you will need to select the Parent property value of the output. For Example:
Get-VM cbslnpcs1 | Get-HardDisk | Select Parent, CapacityGB