VMware Cloud Community
tdubb123
Expert
Expert

show vms with datastores

I want to get my vms on a cluster with their datastores location.

how can i do this?

get-cluster "cluster" | get-vm * | select Name, etc....

0 Kudos
3 Replies
LucD
Leadership
Leadership

Something like this ?

Get-Cluster | Get-VM | 
Select
Name,@{N="Datastore";E={[string]::Join(',', (Get-Datastore -VM $_ | %{$_.Name})}}


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

0 Kudos
tdubb123
Expert
Expert

thank luc. I dont quite understand  what

E={[string]::Join(',', (Get-VM $_ | %{$_.Name})}} does.

it gave me an output like this

Name                 Datastore

-------                                  -------------------

vm                                       vm

but I was able to change it to

get-cluster cluster | get-vm vm* | Select NAme, @{N="Datastore";E={Get-Datastore -VM $_}}

which works now

thank you

0 Kudos
LucD
Leadership
Leadership

That was indeed what it should have been. The join was there in case your VM is spread over multiple datastores? It's corrected now.


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

0 Kudos