Manual XenDesktop Setup Wizard

This post will provide guidance to programmatically creating VM’s, add them to Citrix Provisioning services and finally add them to XenDesktop Controller Catalog and Desktop group.

Restricted to XenServer (Hypervisor), Citrix PVS 5.6+, XenDesktop 5+

  • Make sure the hosting providor (Xenserver) is added in XenDesktop Desktop Studio.
  • Create a Template VM with all the required settings (Dynamic Memory, PXE nic, Write-Cache Disk etc..) on the XenServer.
  • Make a note of the Template UUID, this info can be retried from XenCenter or using xe commands.
  • Create how many machines you want using the following script (needs to be run in the ssh or console session of xenserver host)
    COUNT=1
    #Create 100 VM's 
    while [ $COUNT -lt 101 ]; do
    	VMName=XDWin7`printf "%03d" $COUNT`
    	`xe vm-install new-name-label=$VMName template-uuid=  sr-name-label=`
            #Get Virtual Disk Image (Write-Cache-Disk) UUID
    	VDIuuid=`xe vbd-list vm-name-label=$VMName type=Disk params=vdi-uuid | grep -o '[A-Za-z0-9-]\{36\}'`
            #Set Virtual Disk Image (VDI) Name same as VM Name 
    	`xe vdi-param-set uuid=$VDIuuid name-label=$VMName`
    	let COUNT=COUNT+1
    done	
    

    The code above creates 100 machines named XDWin7001-XDWin7100, I would run them in batches of 30 and choose different Storage repository to prevent performance deterioration as explained in this citrix blog sizing-luns-a-citrix-perspective

  • Get VM Name, PXE Nic MAC Address and VM uuid of the newly created machines
    COUNT=1
    # loop through 100
    while [ $COUNT -lt 101 ]; do
    	VMName=XDWin7`printf "%03d" $COUNT`
    	#Get VM uuid
    	VMuuid=`xe vm-list name-label=$VMName params=uuid | grep -o '[A-Za-z0-9:]\{36\}'`
    	#Get PXE Nic Mac address
    	MAC=`xe vif-list device=0 vm-name-label=$VMName params=MAC | grep -o '[A-Za-z0-9:]\{17\}'`
    	#print VM Name, PXE MAC and uuid
    	echo $VMName,$MAC,$VMuuid
    	let COUNT=COUNT+1
    done			 
    

    run this from a ssh session, makes it easier to copy the result. Paste it in to a notepad and save it as XDVMInfo.txt (C:\Scripts\XDVMInfo.txt)

  • using powershell, create the PVS commands to add these 100 machines
    $data = Get-Content C:\Scripts\XDVMInfo.txt
     
    foreach ($dataline in $data)
    {
     $vmName = $dataline.Split(",")[0]
     $mac = $dataline.Split(",")[1]
     Write-Host "MCLI.exe add Device -r deviceName=$vmName  deviceMac=$mac collectionName=<collectionname> SiteName=<site name>"
    }
    
  • On the PVS box, open the command prompt and navigate to where the MCLI.exe resides (C:\Program Files\Citrix\Provisioning Services). Run the commands generated from the above step in this command prompt.
  • Using PVS console, set the vDisk assignment to these 100 machines (Copy and paste device properties….) and create machine accounts from context menu by selecting all devices in the collection.
  • Copy C:\Scripts\XDVMInfo.txt to XenDesktop Desktop Studio Box and run the following powershell script.
    Add-PSSnapin *Citrix*,*pvs*
    $data = Get-Content C:\Scripts\XDVMInfo.txt
     Set-PvsConnection -server 'PVS IP' -port 54321 -domain 'domain name'
    foreach ($dataline in $data)
    {
     $vmName =  $dataline.Split(",")[0]
     $mac = $dataline.Split(",")[1]
     $sid=(Get-SimplePvsADAccount -domain 'domain name' -name $vmName).sid
     $VMuuid=$dataline.Split(",")[2]
     New-BrokerMachine -CatalogUid <CatalogUid> -HostedMachineId $VMuuid -HypervisorConnectionUid <HypervisorConnectionUid> -MachineName $sid -AdminAddress '<XD-Broker>:80'
    }
    

    CatalogUid and HypervisorConnectionUid can be retrieved using Get-BrokerCatalog and Get-BrokerHypervisorConnection respectively.

  • Using Desktop Studio gui add these new machines to the desired desktop group.

Reason for doing this way is to avoid fast clones created by XenDesktop Setup Wizard and to avoid copying machines when migrating existing machines from one xenserver pool to another or from one SAN to another.

Hope this has been informational. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s