VMware Cloud Community
khanbashi
Contributor
Contributor

Script to extract the VM with the datastore

Can someone help me to extract the VM with the datastore ?

0 Kudos
11 Replies
zXi_Gamer
Virtuoso
Virtuoso

it would be really helpful, if you could provide a little more information on your scenario to help us address your query faster.

In meantime, if you want to extract the VMs information with datastore, you can use commands like:

vim-cmd vmsvc/getallvms [For all registered VMs]

vmdumper -l  [For powered on VMs only]

0 Kudos
admin
Immortal
Immortal

Use the given snip with powerCLI to get the VM - DataStore Associations.

foreach($vm in Get-VM){

       $vm -match "[a-z]+(\d+)" | Out-Null

       $vmNr = $matches[1]

                 $vm | Get-Datastore | %{

                      $_.Name -match "[a-z]+(\d+)" | Out-Null

                      $dsNr = $matches[1]

                      if($vmNr%2 -ne $dsNr%2){

                           Write-Host $vm.Name $_.Name

                                }

                      }

             }

0 Kudos
khanbashi
Contributor
Contributor

thanks so much .

0 Kudos
khanbashi
Contributor
Contributor

Hi

how can i extract it to csv file ?

0 Kudos
a_p_
Leadership
Leadership

Just pipe the output to the Export-Csv cmdlet (see http://technet.microsoft.com/en-us/library/ee176825.aspx)

André

0 Kudos
khanbashi
Contributor
Contributor

Like below

foreach($vm in Get-VM){ 

       $vm -match "[a-z]+(\d+)" | Out-Null 

       $vmNr = $matches[1] 

                 $vm | Get-Datastore | %{ 

                      $_.Name -match "[a-z]+(\d+)" | Out-Null 

                      $dsNr = $matches[1] 

                      if($vmNr%2 -ne $dsNr%2){ 

                           Write-Host $vm.Name $_.Name 

                                } 

                      } 

             } |Export-Csv -Path "c:\vm.csv"

0 Kudos
khanbashi
Contributor
Contributor

any update and also the above script not extract all VMs with the datastore .

0 Kudos
a_p_
Leadership
Leadership

Please take a look at Get List of VMs, Datastores and Folder name per Cluster to see whether this helps.

André

0 Kudos
khanbashi
Contributor
Contributor

thanks but i got blank cumulu for datastore

0 Kudos
a_p_
Leadership
Leadership

Please provide some details about your environment, i.e. ESXi/vCenter version and licensing, the type of storage you are using (e.g. shared/local, block, NFS), ... to find out what may be causing the script to fail in your case.

Did you try to run the script without redirecting the output to a csv file? Same issue?

André

0 Kudos
khanbashi
Contributor
Contributor

ESXi 5.1

vCenter version 5.1

type of storage :EMC -SAN


Did you try to run the script without redirecting the output to a csv file? Same issue? Yes same issue .

0 Kudos