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.
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
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
Hi LucD,
This is awesome.
But if i want to add the hostname & Clustername, how can i insert in this ?
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
Thanks for the quick reply.
I am getting the output of vCenter and host, But not the Cluster name. It is blank.
Further help?
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
Hi LucD,
sorry for the confusion.
The VM, i searched is not part of the cluster. Thanks for extended help..