VMware Cloud Community
Bunty11
Hot Shot
Hot Shot

Datastore usage

Script to know how many virtual machines are currently on these datastores and what is the usage?

i have specific names of datastore names for which i want info. there are 20 datastore for which i need this info

0 Kudos
1 Reply
LucD
Leadership
Leadership

You mean something like this ?

$dsName = "DS*"
Get-Datastore -Name $dsName |
Select Name,@{N="VM#";E={$_.ExtensionData.Vm.Count}},
@{N="UsedGB";E={
       
if($_.ExtensionData.Vm){
           
$dsMoRef = $_.ExtensionData.MoRef
           
$values = @(Get-View -Id $_.ExtensionData.Vm -Property Storage | %{
               
$_.Storage.PerDatastoreUsage | Where {$_.Datastore -eq $dsMoRef} | %{$_.Committed}})
           
if($values){
                [
math]::Round(($values | Measure-Object -Sum | Select -ExpandProperty Sum)/1GB,1)
            }
           
else{0}
        }
    }}

You will have to update the $dsName value to reflect the datastores you want.


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

0 Kudos