Hi all,
First I want to say thanks for all the help provided in these communities. It's been very valuable over the past several years!
I've had the opportunity to work on a neat provisioning script for over a week now and have got it almost ready for release but got stuck on kind of a basic part - picking datastores.
The idea is that we can use this to spin up multiple identical environments on demand - ripe for automation!
We get the number of needed machines is in $clcount, and $dslist might be equal to something like this....
| Name | FreeSpaceGB | CapacityGB |
| SAN-ds-3 | 3,399.11 | 5,119.75 |
| SAN-ds-4 | 1,275.26 | 5,119.75 |
| SAN-ds-2 | 661.813 | 5,119.75 |
| SAN-ds-5 | 292.342 | 5,119.75 |
| SAN-ds-8 | 273.204 | 5,119.75 |
Using my method below works as long as the number of machines is less than the number of datastores available, but would fail if the number of machines exceeds datastores available.
$resources = Get-Cluster "Compute 1"
$OSSpec = Get-OSCustomizationSpec "Base 2012 R2"
$dslist = get-datastore | where {$_.Name -match "SAN" -and $_.FreeSpaceGB -gt 200} | Sort FreeSpaceGB -Descending
$folder = Get-Folder "Lab 2"
$clcount = "17"
$envn = "Lab2-"
$OSSpec = $OSSpec | New-OSCustomizationSpec -Name Temp-Spec -Type NonPersistent -Confirm:$false
foreach ($num in 1..$clcount){
$suffix = "{0:D2}" -f $num
$datastore = $dslist[$num-1]
$OSSpec = $OSSpec | Set-OSCustomizationSpec -NamingScheme fixed -NamingPrefix "APPCL$suffix"
New-VM -Name $envn"APPCL"$suffix -Template $template -OSCustomizationSpec $OSSpec -Location $folder -ResourcePool $resources -Datastore $datastore
}
##End build Client Machines
$OSSpec | Remove-OSCustomizationSpec -Confirm:$false
I know this would be easy to solve with Datastore clusters and SDRS, but I believe that would always pick the datastore with the most free space and you can see our environment could be a bit imbalanced, so I'm trying to build in a little bit more intelligence in distributing these machines across datastores.
Any help or pointers in the right direction would be greatly appreciated!
Use % (remainder of division) to turn $num into something that will be less than the size of dslist:
$datastore = $dslist[$num % $dslist.count]
Then change the sort to ascending.
Use % (remainder of division) to turn $num into something that will be less than the size of dslist:
$datastore = $dslist[$num % $dslist.count]
Then change the sort to ascending.
Perfect, thanks zik! I do want to start with the datastore with most free space which in the array is $dslist[0] so I just modified to:
$datastore = $dslist[($num % $dslist.count)-1]
Thanks again!
