VMware Cloud Community
ChargeOn
Contributor
Contributor
Jump to solution

How do you select VMs NOT in a vapp/resource pool

I have multiple vApps and Resource pools but I am trying to write a script that will take newly restored VMs and place them into a new vApp that is created. When I try the Get-VM command without any parameters it returns all the VMs on the server. Is there a way to get ONLY the VMs that are NOT in a vApp or Resource pool on the Host? 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You do know that every VM is in a ResourcePool?
When you don't see one the VM is in the hidden Resources ResourcePool.
Except for VMs that are part of a VApp, they do not have a ResourcePool assigned.

Meaning the test becomes quite simple, just check if the VM belongs to the Resources ResourcePool.

$clusterName = 'cluster'

$cluster = Get-Cluster -Name $clusterName
$rp = Get-ResourcePool -Name Resources -Location $cluster
Get-VM -Location $cluster | where{$_.ResourcePool.Id -eq $rp.Id} |
Select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You do know that every VM is in a ResourcePool?
When you don't see one the VM is in the hidden Resources ResourcePool.
Except for VMs that are part of a VApp, they do not have a ResourcePool assigned.

Meaning the test becomes quite simple, just check if the VM belongs to the Resources ResourcePool.

$clusterName = 'cluster'

$cluster = Get-Cluster -Name $clusterName
$rp = Get-ResourcePool -Name Resources -Location $cluster
Get-VM -Location $cluster | where{$_.ResourcePool.Id -eq $rp.Id} |
Select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ChargeOn
Contributor
Contributor
Jump to solution

I did not know that thank you!

Reply
0 Kudos