You mean like this?
Get-VMHost |
Select Name,
@{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).host}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD ,
I've ~500 + ESXi hosts. My requirement is
1. Input file with all these ESXi hostnames/IP
2. Script should find the VC name or IP for all the ESXi host and redirect the output to a csv file.
Are all the ESxi nodes connected to the vCenters with those names or IP addresses?
Or can an ESXi node be added to the a vCenter with a FQDN while your list only contains an IP address?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD ,
All the hosts are connected to the vCenter with the FQDN and I've a list of all these hosts which has both FQDN as well as IP.
Ok, assuming you have that list in a CSV with 2 columns, EsxName and IP, you could do
Import-Csv -Path .\esxnames.txt -PipelineVariable row |
ForEach-Object -Process {
Get-VMHost -Name $row.EsxName |
Select Name,
@{N='EsxIP';E={$row.IP}},
@{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).host}}
} | Export-Csv -Path .\result.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD ,
Thank you for the quick help.
I tried running it but it's failing with an error "Get-VMHost : Cannot validate argument on parameter 'Name'.".
I can remove the IP addresses from the input list. Can you please help me with the script only with the FQDN.
Is your input file a CSV with at leats 2 columns named EsxName and IP?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. But I can copy only the FQDN's to a text file and we can pass it as a input.
So it is a simple TXT file with a FQDN on each line?
In that case you can do
Get-Content -Path .\esxnames.txt |
ForEach-Object -Process {
Get-VMHost -Name $_ |
Select Name,
@{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).host}}
} | Export-Csv -Path .\result.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you @LucD .
I've few hosts for which VC information is unknown.
I can login to host and get the VC information from vpxa.cfg. However it would be difficult to login to all such hosts(100+) manually, Would the above script can help in this case?
Are you connected to the vCenter(s) that contain these ESXi nodes?
Check $global:defaultVIServers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry if I was not clear enough earlier.
I've a list of ESXi hosts for which I'm trying to find the VC which they belongs to. Manually logging into each ESXi and checking the vpxa.cfg file would be tedious task. Hence looking for some script which can help achieve this.
Are you saying you are not connected to any vCenter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. The hosts in my input list are from different vCenters and I'd like to find which vCenter they belongs to using the script.
And do you have credentials to connect to all those ESXi nodes?
If yes, you could use the solution I provided in Solved: Re: What vCenter is my host connected to - add NFS... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference