PowerCLI: One-Liner to get VMs, Clusters, ESX Hosts and Datastores


image

With the one-liner below, you’re able to create an overview of your VM’s, Clusters, ESX Hosts and Datastores.

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} 

The following output will be generated:

image

If you add an extra line with the export-csv cmdlet, you can export the output to a CSV file.

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
Export-Csv -NoTypeInformation C:\Scripts\VM_CLuster_Host_Datastore.csv 

If you want, you can import the CSV file into Excel. Excel has some basic filtering options, so you’re able to filter on ESX Host, Cluster etc.

image

About these ads

5 Responses to PowerCLI: One-Liner to get VMs, Clusters, ESX Hosts and Datastores

  1. Pingback: uberVU - social comments

  2. Dumas Philippe says:

    Hi,

    Thanks a lot for this script. It will save me a lot of time to make a report of all my vms and their location.

    Thanks for sharing your job with us.
    God Bless You.

  3. Pingback: powerCLI to get VM, cluster, Host, and datastore « Cyclops' Blog

  4. vinod says:

    This is great script. It helped me a lot.
    Additionally can you suggest how to get Total and free space details against each datastore.

    Thanks!

    • Vinay says:

      how to pass two vm-guest name in single powerCLI to remove from disk.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 1,108 other followers

%d bloggers like this: