Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 225804

Select Random Datastore

$
0
0

In the past I was able to create an array of datastores based on the prefix in the datastore name. From that array, I was able to randomly select which datastore to deploy a virtual machine too.

 

$datastoreArray = @()

    $myds = Get-datastore | where {$_.Name -contains "NFS"}

    foreach ($ds in $myds)

    {

    if (($ds.FreeSpaceMB) -gt ($ds.CapacityMB * .25))

      {

  $datastoreArray += $ds

    }

    }

  if ($datastoreArray.Count -eq 0)

  {

  Write-Host "There is not enough free space to create a Virtual Machine"

  exit

  }

  $dsNumber = ($rnd.next(0,$datastoreArray.count))

  $datastore = $datastoreArray[$dsNumber]

    return $datastore

 

Is there a better way to do this? I would prefer to balance the deployments. Also this does not appear to be working any longer,


Viewing all articles
Browse latest Browse all 225804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>