VMware Cloud Community
papahendo31
Contributor
Contributor

Get-Datastore for vms in a list

Hello I am trying to get the datastore name for a list of vms but not succeeding.

This just seems to pull all the datastores in the entire vcenter

$vmList = Get-Content E:\scripts\migrations\testgetDS-1.txt

foreach ($vm in $vmList) {Get-VM | Get-Datastore | Export-csv c:\Temp\testdsget.csv -NoTypeInformation}

Can anyone give me a little help?  Thanks in advance

0 Kudos
2 Replies
vXav
Expert
Expert

You want a list of the VMs and which datastore they reside on?

If yes try this:

$vmList = Get-VM (Get-Content E:\scripts\migrations\testgetDS-1.txt)

$vmList | select name,@{l="DS";e={$_ | Get-Datastore | select -ExpandProperty Name}}

If not then I misunderstood your request.

0 Kudos