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:
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.
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.
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!
how to pass two vm-guest name in single powerCLI to remove from disk.
For example , storage team allocated lun, but that lun not added any cluser and esx, how to collect not added lun details for entire vc each cluser name wise ?
That’s awesome but how do I get the datastores on separate lines? I want to use a vlookup table within Excel to match datastores against my storage arrays. Having the datastores concatenated (e.g., lun1, lun 2, lun 3) makes that impossible without manually separating them.
Great script, saved me lots of time!
Thanks !!
It helps me a lot !!
Greetings from tora bora afghanistan I was looking for this command for awhile
great script. Is there any way to target a specific folder?
I found the script run very slow, I have 40 ESX host, and about 1000 vms. I run this script for about 40 minutes, Could it run more quickly? If I donot care the Performance consume on the vCenter or the client I run the scripts. Thanks!
I don’t know powershell, but it’s definitely spawning internal loops that are redundant for the “Get-Cluster -VM” filters. If you make them explicit it’s much faster:
foreach ($cluster in Get-Cluster)
{
$hosts = $cluster | Get-VMHost
foreach ($each_host in $hosts)
{
$vms = $each_host | Get-VM
foreach ($vm in $vms)
{
… etc
You can probably condense the enumeration of each child object to occur within the “foreach” line, but I don’t know how.
Thank you so much it’s very use full.
I wan to extract the mismatch details between host and data store