VMware Cloud Community
samselvan
Contributor
Contributor

How to find VM and it's corresponding datastore using powerCLi?

am trying to get the report of VM and it's details.

I have written a powercli script which would find VM name, IP  address, Poweron status and snapshot list. But i have no idea how to  find the datastore associated with the VM.

How to get VM name and it's associated datastore?

0 Kudos
2 Replies
LucD
Leadership
Leadership

One way of doing that is

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


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

0 Kudos
tigerdeccan
Enthusiast
Enthusiast

another way would be like this . this will also detail the host information

Connect-VIServer

44.128.164.101

Get-VM

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

@{N

="ESX Host";E={Get-VMHost -VM $_}}, `

@{N

="Datastore";E={Get-Datastore -VM $_}}

0 Kudos