kavi_gunn
Contributor
Contributor

vCenter Inventory

Hi,

I need a script or command in order to gather the following infos from a list of VM (datacenter name, cluster name, vm name and vm uuid).

I have used this command which works fine :

Get-Cluster **** | Get-VM | Select @{N=”Datacenter”;E={Get-Datacenter -VM $_}}, @{N="Cluster";E={Get-Cluster -VM $_}},Name, @{N="VMUUID";E={(Get-View $_.Id).config.uuid}} | Export-CSV "C:\DC-$(Get-Date -f ddMMyyyy).csv" -NoTypeInformation

Except that now I need to use a list of VM from a text file to retrieve the above infos.

Could you please help me out?

Tags (1)
0 Kudos
7 Replies
diegodco31
Leadership
Leadership

Hi

I always use rvtools, think is more simple.

https://www.robware.net/rvtools/

Diego Oliveira LinkedIn: http://www.linkedin.com/in/dcodiego
0 Kudos
kavi_gunn
Contributor
Contributor

Thanks for your suggestion Diego. RVTools is a great tool but it retrieves a full list of VMs where you may have duplicate vm names such as abc, abc- or abc_.

Based upon the vm.txt list, I'll be able to gather the necessary info needed.

0 Kudos
a_p_
Leadership
Leadership

Welcome to the Community,

Please see whether Re: Script to get VMs name, host and IP filteredis what you are looking for.

Hint: Whenever searching for a script that works on vSphere, include PowerCLI and lucd as keywords in your search.

André

0 Kudos
a_p_
Leadership
Leadership

Discussion moved from VMware vCenter™ to VMware PowerCLI

0 Kudos
LucD
Leadership
Leadership

This combines the .txt file and your original code.
The text file assumes 1 VM name per line.

Get-VM -Name (Get-Content -Path vmnames.txt) |

Select @{N = ”Datacenter”; E = {(Get-Datacenter -VM $_).Name}},

   @{N = "Cluster"; E = {(Get-Cluster -VM $_).Name}}, Name,

   @{N = "VMUUID"; E = {$_.ExtensionData.config.uuid}} |

Export-CSV "C:\DC-$(Get-Date -f ddMMyyyy).csv" -NoTypeInformation


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

0 Kudos
kavi_gunn
Contributor
Contributor

Thanks a.p it works for me hurray! Smiley Happy

Is there any possibility to remove duplicate vm entries if ever it was present in the vm text file list unknowingly?

0 Kudos
a_p_
Leadership
Leadership

Yes, you can use e.g. Get-Unique to do this.

André

0 Kudos