VMware Cloud Community
GregL75
Enthusiast
Enthusiast

Add VMs to Desktop pools

Currently building a View 4.6 env in parallel to our existing 4.1 for a PCoIP proof of concept. Once we are ready to switch over this will include to register the vm into new pools in the 4.6 env.

I did not found anything really obvious so far... which tells me I must have miss something.

Is there a cmdlet to add a vm to a pool and set a user entitlement.

Thanks All

G.

Reply
0 Kudos
11 Replies
RvdNieuwendijk
Leadership
Leadership

I'm not a View user, but from Alan Renouf's blog post VMware View 4.5 – More PowerShell Cmdlets I think you need the Add-PoolEntitlement cmdlet to set a user entitlement.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
mattboren
Expert
Expert

Hello, GregL75-

There are View PowerCLI cmdlets available to you on your View Connection server(s).  While they are not quite a refined as the regular PowerCLI, you should be able to use them to accomplish what you want.

The "PowerShell Integration with VMware View 4.5/4.6" tech paper at the Technical Resource Center should be quite helpful in getting you started with View PowerCLI.

One major drawback to this tool right now is that it must run on a View Connection server that is part of the View environment.  You can use PSRemoting, but it's not quite the same.  But, even still, it is definitely a helpful tool.

For adding a VM to a pool (sounds like a manual pool), see the Add-ManualPool cmdlet.

For the user entitlement, see the Add-PoolEntitlement cmdlet (like Robert said).  Again, not quite as refined as it hopefully will be -- this cmdlet takes pool_id and the SID for the AD user/group to entitle.  The MS Get-User cmdlet will do there for getting the SIDs, or the Quest QAD cmdlet Get-QADUser will as well.

Enjoy.

GregL75
Enthusiast
Enthusiast

I will give those a try, thanks for info.

When I read the document initially I was understanding it differently:

Add-ManualPool to create a pool which requires an inititial vm.

Add-PoolEntitlement entile a user to a Pool but not a user to a specific VM.

I will play with those this PM and keep you guys posted

Cheers

Reply
0 Kudos
GregL75
Enthusiast
Enthusiast

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).”
}
})

Reply
0 Kudos
GregL75
Enthusiast
Enthusiast

I tested Add-ManualPool... Looks like it only allows you to add VMs to the pool at the time of creation

Reply
0 Kudos
mattboren
Expert
Expert

Hello, GregL75-

Ha, yes, code that comes to have terrible formatting -- definite fun.

Ok, you want to add a VM to an existing pool -- I read your previous statements to mean that you would be creating a new pool from an existing VM.  As you point out -- not the same.

And it seems that you are talking about a VM assignment (assigning a user to a VM) instead of entitling a user to a pool.  So, yes, vdmadmin.exe would be the way to go for making a VM assignment, vs. the Add-PoolEntitlement cmdlet that we mentioned.

Yeah, no signs of a AddVMToADAM() function really anywhere on the web that I see (except for that doc, and your post).  Anyone from VMware care to chime in about that function?

Sorry, not very helpful, I know.  Is this something that you can change the need a bit -- that is, instead of creating a Manual pool and adding existing VMs to it, can you create a new Automatic pool from the given parent VM and allow View to create the VMs for the pool?  Trying to think of other ways that would not rely on that [missing] function.

sevenply
Contributor
Contributor

Do you still need help with that topic? I found out how to add VM's via the powerCli Snap in and how the function AddVMToADAM () looks like.

Reply
0 Kudos
ashvitech
Contributor
Contributor

Hi,

I dont see any easy way to add VMs to existing pool straighway. Can you please explain how to do it through cmdlets?  The AddVMToADM <AddRemoveVMs.ps1> is not working for me also.

For me,

1) Create a new pool with VMs    (New)
Example
Add-ManualPool  <with bunch of Vms vm id list>

2) To update the existing pool

The UpdateManualPool is just updates the pool configuration, not VMs. I have to remove the pool and add it with new vm list.

- Remove-Pool 1001 (ex)
- Add-ManualPool 1001  <new vm id list>


I want easy way to add/remove VMs to/from existing pool.  Appreciate your help.

Thansk,
Ashok

Reply
0 Kudos
deadmetal
Contributor
Contributor

Hi there

I would still like to know how you scripted, please tell

Best regards

Gary

Reply
0 Kudos
mxha
Contributor
Contributor

Hi,

could anyone please give me the AddVMToADAM function or something else?

I need a script to add vm names(desktop names) to an existing Pool.

Thanks

regards

Max

Reply
0 Kudos
sevenply
Contributor
Contributor

Hello,

well this is kind of tricky. You have to work with ADSI commands to get that done. I wrote a prototype which works for me. Of course its not dynamic yet.

VMWare stores the specific information like which machine is in which pool in the AD. You need to update this information. It did it like that:

##Pool

$pool_id = (get-Pool -pool_id testPool).pool_id

##VM

$VmObject = get-DesktopVM -name Test_Client_01

##you find the machine_id in the ADSI.

$machine_id = "9b432dd5-3ab9..."

$poolObject = [ADSI]("LDAP://localhost:398/cn="+$pool_id+",ou=Applications, dc=vdi,dc=vmware,dc=int")

$serverGroup = [ADSI]("LDAP://localhost:398/"+$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")

     $machineList = $serverGroup.get("pae-MemberDN")

     if($machineList)

     {

          $machineListAl = New-Object System.Collections.ArrayList(,$machineList)

     }

     else

     {

          $machineListAl = New-Object System.Collections.ArrayList

     }

     $null = $machineListAl.Add("CN="+$machine_id +", OU=Servers, dc=vdi, DC=vmware,dc=int")

     $serverGroup.SetInfo()

}

else

{

     ##

}

Reply
0 Kudos