The WhitePaper for 4.5 and 4.6 provide a piece of code that can be imported with a function AddVMtoPool.
btw... always distribute your code inside a pdf it makes the formatting a real pleasure once you are in a text editor ;-)
I imported the module using Import-Module and I now have access to AddVMtoPool
The snipet seems to invoke AddVMToADAM which is not recognized
"The term 'AddVMToADAM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
A get-command does not list AddVMToADAM
So here I am a little bit stuck, not being very familliar with powercli, looks it is calling a function that has not been provided.
Also getting an error on the trap exception section code. I will revisit that...
For the entitlement, looks like the vdmadmin.exe -L -d -m -u is the best bet
From the whitepaper:
# AddRemoveVMs.ps1
# Functions for adding and removing VMs in View Pools.
# WARNING: These functions manipulate the ADAM directory directly, which may cause faults in an environment if used incorrectly.
#### Add a VM to a pool
#### Parameters:
#### $VMObject:Virtual Machine object for VM to be added (obtained from Get-DesktopVM)
#### $pool_id:Name of pool to which VMObject should be added
#### Example Usage: AddVMToPool (Get-DesktopVM -Name <vmname>) <pool_id>
function AddVMToPool
{ param ($VMObject, $pool_id)
if($VMObject.vm)
{
if($VMObject.isInPool -eq “true”)
{
Write-Error (“The specified VM (“ + $VMObject.Name + “) is already assigned to a pool.”)
}
else
{
# Get the GUID for this VM’s entry in ADAM, creating an entry ifn ecessary
$machine_id = $VMObject.machine_id
if(-not $machine_id)
{
$machine_id = AddVMToADAM $VMObject
}
# Locate the server group for the pool to which this VM belongs
$poolObject = [ADSI](“LDAP://localhost:389/cn=” + $pool_id + “,ou=Applications,dc=vdi,dc=vmware,dc=int”)
$serverGroup = [ADSI](“LDAP://localhost:389/” + $poolObject.get(“pae-Servers”))
# Add the distinguished name of the VM’s ADAM entry to the server group
if($serverGroup)
{
$machineName = $VMObject.Name
$serverGroupId = $serverGroup.get(“cn”)
Write-Output (“Adding $machineName to pool $pool_id”)
$machineList = &
{
trap [Exception]
{ continue;
}
$serverGroup.get(“pae-MemberDN”)
}
if($machineList)
{
if($machineList.Count -gt 1)
{
$machineListAL = New-Object System.Collections.ArrayList(,$machineList)
}
else
{
$machineListAL = New-Object System.Collections.ArrayList
$null = $machineListAL.add($machineList)
}
}
else
{
$machineListAL = New-Object System.Collections.ArrayList
}
$null = $machineListAL.Add(“CN=” + $machine_id + “,ou=Servers,dc=vdi,dc=vmware,dc=int”)
$serverGroup.put(“pae-MemberDN”,$machineListAL.ToArray())
$serverGroup.SetInfo()
}
}
}
else
{
Write-Error “The object passed as a parameter was not a valid VM object (a valid object would be returned by Get-DesktopVM).”
}
})