Finding DNS Name of all VMware Guests

Recently, I needed to discover the DNS names of all machines running in our various VMware environment. Enter PowerCLI.

PowerCLI is the gift of VMware to us IT people who would rather script than click a button. It’s nothing groundbreaking, but I figure I am not the only one to have to do this, so might as well make it available.

Connect-ViServer -Server [vcenter]

This can be run on for each Vcenter and each left as “default.” Doing this will cause any further command that doesn’t have a specific Vcenter designated to run against all connected Vcenters.

Get-Vm | select Name, Powerstate, @{N="IPAddress"; E={$_.Guest.IPAddress[0]}}, @{N="DnsName"; E={$_.ExtensionData.Guest.Hostname}} | Export-CSV [path for CSV] -NoTypeInformation

This gets all the VMs from all connected Vcenters and dumps Name, Powerstate, IP Address, and Hostname into a CSV-in as few as two lines. Now you can run whatever you need on the CSV from there (more on that later).

You can easily modify this to make a scheduled task and set up all kind of reporting. Just install PowerCLI.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s