Hi Everyone,
I got the following script to list all of the VM per datastore, but somehow it doesn't display datastore (blanks) for certain VMs ?
Get-Datacenter | Get-VM | %{ $_.Name + " - " + (($_ | Get-Datastore | select Name).Name) | sort Name } | ft -AutoSize
any kind of help would be greatly appreciated.
Kind Regards,
AWT
Could it be that you have some guests that have connections to 2 or more datastores ?
Try this
Get-Datacenter | Get-VM | %{ $vm = $_ Get-Datastore -VM $vm | %{ $vm.Name + "-" + $_.Name } } | ft -AutoSize
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could it be that you have some guests that have connections to 2 or more datastores ?
Try this
Get-Datacenter | Get-VM | %{ $vm = $_ Get-Datastore -VM $vm | %{ $vm.Name + "-" + $_.Name } } | ft -AutoSize
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ah yes,
you're right let me try this first.
Yes it works man, thanks for the help !
Kind Regards,
AWT
Hi LucD,
How would I get this output in to a CSV file?
Thanks in advance.
If you pipe this as-is to a CSV you will just get a CSV file with the length of each string.
The solution is to use a Select-Object and pass objects to the Export-CSV cmdlet.
Something like this for example
Get-Datacenter | Get-VM | %{ $vm = $_
Get-Datastore -VM $vm |
Select @{N="Name and DS";E={$vm.Name + "-" + $_.Name}} } | Export-Csv C:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference