Automation

 View Only
  • 1.  Datastore usage

    Posted Feb 06, 2014 07:57 PM

    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



  • 2.  RE: Datastore usage

    Posted Feb 06, 2014 08:34 PM

    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.