VMware Cloud Community
cmjellis
Enthusiast
Enthusiast
Jump to solution

select parameters are wrong - looking for server - reports servername and harddisk

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

1 Solution

Accepted Solutions
deang1609
Enthusiast
Enthusiast
Jump to solution

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

Dean Grant Blog: deangrant.wordpress.com | Twitter: @dean1609 | GitHub: https://github.com/dean1609

View solution in original post

Reply
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
deang1609
Enthusiast
Enthusiast
Jump to solution

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

Dean Grant Blog: deangrant.wordpress.com | Twitter: @dean1609 | GitHub: https://github.com/dean1609
Reply
0 Kudos