Adding a Published Application to multiple Delivery Groups in XenDesktop 7.x

Although assigning a Published Application to multiple Worker Groups in XenApp 6.x was a fairly straightforward task, the same activity is not as intuitive in XenDesktop 7.x. The Citrix Product Documentation isn’t exactly crystal clear on the process either. As such, I thought I would take the opportunity to document the process here.

Firstly, I am using XenDesktop 7.1 in my example below and I haven’t found a way to do this using the GUI, so we have to use PowerShell. I haven’t validated this for 7.0 or 7.5, although I assume the process will be the same.

After creating the target Delivery Groups, the first thing to do is discover and publish the required application(s) to the first Delivery Group using the Citrix Studio Console. I suggest using this method as it is quick and easy. Alternatively PowerShell can be used to create the application. I will detail at the end of the article.

Once you have a Published Application you will need to launch PowerShell, again I find this easiest to do from the Citrix Studio Console. The following command will assign the named Published Application to the Delivery Group specified, much like you would do with XenApp 6.x and Worker Groups. This can be repeated as required.

Note: Published Applications can only be assigned to Delivery Group with a type of ‘Applications Only’ or ‘Desktops and Applications’

Add-BrokerApplication -Name "Publised App Name" -DesktopGroup "Delivery Group 1"

In addition to this a priority can also be assigned. By default the priority is 0. 0 is the highest priority. To assign a priority, use the -priority attribute as seen below. The priority can be used to either load balance the group, when both Delivery Groups have the same priority, or in failover order as the priority descends.

Add-BrokerApplication -Name "Publised App Name" -DesktopGroup "Delivery Group 1" -priority 1

To add a Published Application using PowerShell use the following Cmdlet:

Add-BrokerApplication -BrowserName "Publised App Name" -DesktopGroup "Delivery Group 1"

I hope this helps.

Custom Condition Using PowerShell to Check if an ICA Session is a Published Destkop

Recently I had a specific need to identify if a Citrix XenApp session was a published desktop using AppSense Environment Manager. AppSense Environment Manager has built-in conditions to apply to a particular published application, however I needed to know if the session was just a published desktop so this wasn’t going to work. To do this I created the following PowerShell script to be used as a custom condition. I hope this helps anyone else in a similar position.

$sessionid = query session | Select-String -Pattern ">"
$sessionid = $sessionid.ToString()
$sessionid = $sessionid.Substring(9,9)
$sessionid = $sessionid.trim()
$publishedapp = (Get-ItemProperty  HKLM:\SOFTWARE\Citrix\Ica\Session\$sessionid\connection).InitialProgram
If ($publishedapp) {exit (0)} else {exit(1)}

Automating diskpart commands using PowerShell

A small script to generate a ASCII text file to automate diskpart. Using this with PSExec can make a quick yet powerful tool.

This script in particular automates the process of rescanning a disk and extending the select volume in Windows Server 2008 or Windows 7.

$script = $Null
$script = @"
rescan 
select disk 0
select volume 2
extend
exit
"@
$script | Out-File -Encoding ASCII -FilePath "c:\Diskpart-extend.txt"

diskpart.exe /s c:\Diskpart-extend.txt

Checking for VM Snapshots in vCenter using Powershell

A small script to output snapshots per VM.

Connect-VIServer myserver.fqdn.com
Write "#####START#####"
$vms = $null
$vms = Get-VM
foreach ($vm in $vms) {
$snapshots =  Get-Snapshot -VM $vm
$i = 1
foreach ($snapshot in $snapshots) {
$i = $i + 1
if ($i -ge 2) {
$vm.name
$i
#$snapshot.Name
#$snapshotTable =  @($vm.Name) # | Sort-Object {$_.name}
#$snapshotTable
}
}
}
Write "#####DONE######"

You can also list snapshots based on a name containing any value using the following code:

Get-VM | Get-Snapshot | Where-Object {$_. -contains "searchString"}

How to add datastores to single host in vCenter using Powershell

Connect-VIServer myserver.fqdn.com 
$VMHost = (Read-Host "Please enter the name of your the ESX Host you wish to configure")

$shellObject = new-object -comobject wscript.shell 
$intAnswer = $shellObject.popup("Do you want to add the datastores?", 0,"Add datastores - remember you must have added the hosts on the storage",4) 
If ($intAnswer -eq 6) {
Write "Creating Datastores on $VMHost…" 
New-Datastore -Nfs -VMHost $VMHost -Name datastorename -Path /vol/volname -NfsHost 10.10.10.10
New-Datastore -Nfs -VMHost $VMHost -Name datastorename -Path /vol/volname -NfsHost 10.10.10.10
} else {
Write "Skipping Datastores on $VMHost…" 
} 

List all VMs with a memory limit set in vCenter using Powershell

This script lists all VMs with a memory limit set in Resource Manger in a given VMWare cluster.

Connect-VIServer myserver.fqdn.com 
Get-Cluster $Cluster | Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne "-1"}

If you want to clear all memory limits and set them to unlimited use the following code

Connect-VIServer myserver.fqdn.com 
Get-Cluster MyCluster | Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne "-1"} | Set-VMResourceConfiguration -MemLimitMB $null

The same can also be done for the CPU management using CpuLimitMhz attribute.

Bulk add a VMNetwork to a ESX Cluster

A quick powershell script to add a new VM Network to an existing ESX Cluster.

Connect-VIServer vsphere.example.com 
$Cluster = (Read-Host "Enter cluster name")
$vSwitch = (Read-Host "Enter vSwitch to add the port group to")
$PortGroup = (Read-Host "Enter vmNetwork name")
$vLANPortGroup = (Read-Host "Enter vmNetwork vLAN number")
Get-Cluster $Cluster | Get-VMHost -State "Connected" | Get-VirtualSwitch -Name $vSwitch | New-VirtualPortGroup -Name $PortGroup -VLanId $vLANPortGroup