VMware Cloud Community
GaneshNetworks
Jump to solution

Command to get VC, DC, Clu and ESXi name of one VM

Commanders:

Currently am managing 8 VCs (vSphere 5) through vSphere clinet. So searching one particular VM in all VCs is became horrible in this situation. Thinking of using PowerCLI to make this job easier. So I installed PowerCLI 5 and connected all my VCs.

I need a command line to search a VM, which returns the VC Name, Datacenter Name, Cluster Name and ESXi Hostname. I know that its a one line job and very easy for you guys to answer.

Thanks in advance!!!

~GaneshNetworks™~ If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this, it's not the fastest way, but it should give you all the values

Get-VM MyVM |
Select Name,@{N="ESX";E={$_.VMHost.Name}},
 
@{N="Cluster";E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
 
@{N="Datacenter";E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
 
@{N="vCenter";E={$_.ExtensionData.Client.ServiceUrl.Split('/')[2]}}
 


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this, it's not the fastest way, but it should give you all the values

Get-VM MyVM |
Select Name,@{N="ESX";E={$_.VMHost.Name}},
 
@{N="Cluster";E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
 
@{N="Datacenter";E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
 
@{N="vCenter";E={$_.ExtensionData.Client.ServiceUrl.Split('/')[2]}}
 


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

0 Kudos
GaneshNetworks
Jump to solution

You saved me from big  trouble. I owe you zillion bucks!!!

~GaneshNetworks™~ If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos