Xaden50
Contributor
Contributor

Get IP address and DNS for all VMs

Hey all,

Sorry in advance, but I'm terrible with scripting in general. I'm trying to get name, powerstate, IP address and DNS as it shows in vSphere into a CSV file. So far I have:

get-vm | select Name,PowerState,IPAddress,DNSAddress | cexport-csv c:\temp\vc5_austin_vm_list.csv

Obviously IP address and DNS address aren't the right syntax. Help?

Thanks in advance.

10 Replies
Xaden50
Contributor
Contributor

Only the IPv4 address, btw    

0 Kudos
kunaludapi
Expert
Expert

get-vm | select name, Powerstate, @{N="IPAddress"; E={$_.Guest.IPAddress[0]}}, @{N="DnsName"; E={$_.ExtensionData.Guest.Hostname}}

Check this one will be helpful

vGeek: Extended VM inventory using powercli

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
virtubhuvan
Contributor
Contributor

It works and shows the IP and VM host name.

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Can we able to get the ESXi host name and Cluster along with this. Please help to check

Regards

Narayanan.

0 Kudos
yosingh
Enthusiast
Enthusiast

Try this to get hostname and cluster
get-vm | select name, Powerstate, @{N="IPAddress"; E={$_.Guest.IPAddress[0]}}, @{N="DnsName"; E={$_.ExtensionData.Guest.Hostname}}, VMhost, @{N="Cluster"; E={$_.VMhost.Parent.Name}}

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Thank you yosingh..Works Perfectly.

I have added datastore field also and works that also.

Can we able to append some more available fields like cpu, memory,disks & usage if possible in the same line.

Regards

Narayanan.

0 Kudos
zubersmemon
Contributor
Contributor

Use below script to get all the required information you want.

 

Get-VM | Select-Object Name,PowerState,@{N="IPAddress"; E={$_.Guest.IPAddress[0]}}, @{N="DnsName"; E={$_.ExtensionData.Guest.Hostname}},NumCpu,MemoryGB,ProvisionedSpaceGB,UsedSpaceGB,Guest,VMHost,Notes | Export-CSV ALL_CLuster.csv -NoTypeInformation

0 Kudos
nachogonzalez
Commander
Commander

Do you need to script it?

Can you just use RVtools and remove the fields you don't need?


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

Tags (1)
0 Kudos
LucD
Leadership
Leadership

Really @nachogonzalez ?!?
You did notice that this community is located under Automation.


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

nachogonzalez
Commander
Commander

Nope, I did not.
Got here from the homepage.
Apologies

0 Kudos