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?
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
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
I did not know that thank you!