I developed a function that allows administrators to create multiple VDI VMs using a VM template, guest OS profile on vmm 2012 R2.
I am trying to figure out a way to add these 2 goals to my function.
The function should validate whether the IP pool has enough available IPs available for VM’s to communicate. In my use case, the IP pool has 508 IPs available.
Names of the VM’s should not exceed 15 characters.
Time to switch to IPv6! (grin). You’ll never run out!
But seriously.
Let’s start with the easy one. If the VM name is in $name, then $name.length will tell you how many characters it is. You can just check to see if that’s over your limit or not.
You should be able to do something like…
Get-SCIPAddress | Where State -eq ‘Assigned’ | Measure
And the resulting object will have a Count property showing number of assigned addresses. That’ll tell you if you’re past your limit, right?
I then used the If statement and the less than switch against my count parameter, to check and see if the number of machines would have enough ip’s in the pool and throw a error.
Check if there are enough IPs.
if($availableaddressesObj -lt $count) {
Write-Host “There is not enough IP addresses available in the pool, ensure that the IP pool has enough IPs and retry function.” -ForegroundColor Yellow
break
}
I did something similar for the computer name check as well. I can send you a copy of the function to provide you with more context.