VMware Cloud Community
nava_thulasi39
Jump to solution

Searching VMs in multiple VCs

Hi,

I always connect with multiple VCs at a time to search VMs (4 to 5 VCs).

Eventhough I found a VM, i need to re search using the cluster name or host name to find the VC name again.

So is there any possibility to get the VM with the details in which VC it resides.

I usually do like this...

connect-viserver vc01, vc02, vc03, vc04 -user username -password pass

Then will use get-vm to find the VM.

We don't have good naming convention to find the VC using Cluster name, VM name even the host name.

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can get the vCenter like this

Get-VM |
Select Name,@{N="vCenter";E={$_.Uid.Split(":")[0].Split("@")[1]}}


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

You can get the vCenter like this

Get-VM |
Select Name,@{N="vCenter";E={$_.Uid.Split(":")[0].Split("@")[1]}}


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

0 Kudos
nava_thulasi39
Jump to solution

Hi LucD,

This is awesome.

But if i want to add the hostname & Clustername, how can i insert in this ?

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VM |
Select Name,
@{N="vCenter";E={$_.Uid.Split(":")[0].Split("@")[1]}},
@{N="Host";E={$_.VMHost.Name}},
@{N="Cluster";E={
 
$parent = Get-View $_.ExtensionData.ResourcePool
 
while($parent.parent -and $parent -isnot [VMware.Vim.ClusterComputeResource]){
   
$parent = Get-View $parent.parent
  }
 
if($parent.Parent){$parent.Name}
}}


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

0 Kudos
nava_thulasi39
Jump to solution

Thanks for the quick reply.

I am getting the output of vCenter and host, But not the Cluster name. It is blank.

Further help?

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, just tried it again in my test environment, and I only get a blank for the Cluster property when the VM is not in a cluster.

Could you perhaps attach a screenshot of the Hosts & Clusters Inventory view from the vSphere client ?

And where I could see where the VMs are actually located.

If you don't want make your infrastructure public in this way, send me a PM and we will arrange something.


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

nava_thulasi39
Jump to solution

Hi LucD,

sorry for the confusion.

The VM, i searched is not part of the cluster. Thanks for extended help.. Smiley Happy

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos