Can someone help me to extract the VM with the datastore ?
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]
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
}
}
}
thanks so much .
Hi
how can i extract it to csv file ?
Just pipe the output to the Export-Csv cmdlet (see http://technet.microsoft.com/en-us/library/ee176825.aspx)
André
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"
any update and also the above script not extract all VMs with the datastore .
Please take a look at Get List of VMs, Datastores and Folder name per Cluster to see whether this helps.
André
thanks but i got blank cumulu for datastore
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é
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 .