VMware Cloud Community
DavidMacCO
Contributor
Contributor

PowerCLI to find vCenter for list of VM's

We have multiple vCenters and I am trying to find a way via PowerCLI to search from a list of VM's (CSV File) to find the vCenter that VM is in. 

0 Kudos
2 Replies
scott28tt
VMware Employee
VMware Employee

There is an area of the Communities dedicated to PowerCLI, I have reported your post to the volunteer moderators asking them to move it there.

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

You could do (assuming the VM names are in a column named 'Name')

Import-Csv -File .\vmnames.csv -UseCulture |
Foreach-Object -Process {
  Get-VM -Name $_.Name |
  Select Name,
    @{N='vCenter';E={([System.Uri]$_.ExtensionData.Client.ServiceUrl).Host}}
}

 


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

0 Kudos