Hey Guys,
Perhaps im doing something really wrong here, but everytime I run this command, all I get is the VM, not the property:
$VM | Where-Object {($_.Guest.Disks | Where-Object {$_.Path -eq 'C:\'}).CapacityGB}
Any thoughts?
You can.
First loop through all the VMs in the $VM variable, then extract the object that represents the C-partition into variable $a.
Once done, you access the properties via the $a variable
$VM | %{
$a = $_.Guest.Disks | Where-Object {$_.Path -eq 'C:\'}
$a.CapacityGB
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
You have to place the elements from $_.Guest.Disks in the pipeline, then filter what gets through with the Where-clause, and finnally extract the property you want
$VM | Select Name,
@{N='C Size';E={($_.Guest.Disks | Where-Object {$_.Path -eq 'C:\'}).CapacityGB}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That seems to work a treat, thank you :smileygrin:
I take it there is no way to get the value without having to select the name?
I stored the whole thing into a variable like this:
$a = ($VM | Select Name, @{N='SystemDisk';E={($_.Guest.Disks | Where-Object {$_.Path -eq 'C:\'}).CapacityGB}})
Then retrieve the value like this:
$a.SystemDisk
I was hoping to get the value in one line of code, can it be done?
Thanks again :smileygrin:
You can.
First loop through all the VMs in the $VM variable, then extract the object that represents the C-partition into variable $a.
Once done, you access the properties via the $a variable
$VM | %{
$a = $_.Guest.Disks | Where-Object {$_.Path -eq 'C:\'}
$a.CapacityGB
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thats even better than what I wanted :smileygrin:
Now I can pick off parameters from each server with a system disk :smileygrin:
Thanks again LucD :smileygrin:
Your legendary skills make this community such an awesome place to come to for assistance :smileygrin: