The idle pool settings of a desktop group define how many virtual desktops should be kept in an idle state at any given time. When a user launches a virtual desktop, they are given one of the idle machines and another machine is started on the backend to attempt to keep the number of idle machines the same. Keeping machines in an idle state allows users to connect to them quicker since they are already powered on. However, you don’t want all of the virtual desktops to remain idle at all times of the day since that would use up uneeded resources and be more expensive to maintain.

Ideally, you want to have just as many idle machines that are necessary to support the given load at various parts of the day. When users first arrive in the morning, you will have peak times that require more idle machines than during other parts of the busines day. During regular business hours you will need more idle machines than in non-business hours. The XenDesktop Delivery Services Console allows each desktop group to maintain its own set of idle pool settings (peak hours, business hours, non-business hours, business days of the week, etc.) for controlling how many virtual desktops are kept idle at any given time. These settings are shown in the screen shot below.

For those of you that have maintained a XenDesktop farm for some time, you may have noticed the need to have seasonal changes to the idle pool settings at various times of the year. For example, virtual desktop use may increase at the end of each quarter to support higher demand from the sales teams. Virtual desktop use may also decrease during World Cup season (you know you are out there ). The purpose of this article is to demonstrate how you can automate the changing of the idle pool settings via a PowerShell Script. By automating this configuration, you ensure that you have the optimal idle pool settings both during the week and throughout the entire year.

This is the fifth blog in a series on how to use the XenDesktop 4 PowerShell SDK. In the first blog, I provided info on how to set up your XenDesktop PowerShell environment so that you could run these scripts. If you haven’t done that yet, please visit that article first. In the last blog, I discussed how enable and disable a desktop group via PowerShell. For a complete list of topics that I will be covering in this blog series, see the bottom of this article.

Script Goals
Before I go into the script, I want to provide a quick scenario for what I’m looking to do. The table below provides details on the current idle pool settings that I have configured for a desktop group called “Windows XP”. (In fact, the screen shot at the top of this article depicts the settings in the Current Value column). It’s now getting closer to holiday season and I know I will have a bigger load that I need to support. So I want to increase the idle counts for the peak hour times and business hour times. I also want to change the peak hours and business hours to a larger time window and add Saturday and Sunday as business days. The new settings that I want to apply to the desktop group are listed in the New Value column.

Setting Current Value New Value
Peak Idle Count 3 virtual desktops 5 virtual desktops
Business Hours Idle Count 2 virtual desktops 3 virtual desktops
Out of hours Idle Count 1 virtual desktop 1 virtual desktop
Peak Hours Start 8:30am 8am
Peak Hours End 9:30am 10am
Business Hours End 6pm 8pm
Time Zone Central Standard Time Central Standard Time
Business Days Monday through Friday only Every day of the week

PowerShell script for updating the idle pool settings of a desktop group
The sample script below demonstrates how to update the idle pool settings for a desktop group.

#*************************************************************************************
#Update the idle pool settings of a desktop group
#*************************************************************************************

#Add the XenDesktop snap-in to the current Powershell session
Add-PSSnapin <span class="code-quote">"XdCommands"</span>

#Set up variables <span class="code-keyword">for</span> the script
$strDDCAddress = <span class="code-quote">"10.10.10.56"</span>
$strDesktopGroupName = <span class="code-quote">"Windows XP"</span>

#Get a particular desktop group
$xdgroup = Get-XdDesktopGroup -Name $strDesktopGroupName -AdminAddress $strDDCAddress -HostingDetails

#Update the idle pool settings <span class="code-keyword">for</span> the desktop group
$xdgroup.HostingSettings.OutOfHoursIdleCount = 1
$xdgroup.HostingSettings.BusinessHoursIdleCount = 3
$xdgroup.HostingSettings.PeakHoursIdleCount = 5
$xdgroup.HostingSettings.PeakHoursStart = [Timespan] <span class="code-quote">"8:00:00"</span>
$xdgroup.HostingSettings.PeakHoursEnd = [Timespan] <span class="code-quote">"10:00:00"</span>
$xdgroup.HostingSettings.BusinessHoursEnd = [Timespan] <span class="code-quote">"20:00:00"</span>
$xdgroup.HostingSettings.IdleTimesTimeZone = [<span class="code-object">System</span>.TimeZoneInfo]::GetSystemTimeZones() | where { $_.StandardName -like <span class="code-quote">"Central Standard Time"</span> }
$xdgroup.HostingSettings.BusinessDays.Add(<span class="code-quote">"Saturday"</span>)
$xdgroup.HostingSettings.BusinessDays.Add(<span class="code-quote">"Sunday"</span>)

#Apply the change to the DDC
Set-XdDesktopGroup $xdgroup

#Verify the update (can also look in the Delivery Services Console)
echo $xdgroup.HostingSettings

After executing the script, you can open the Delivery Services Console and verify that the desktop group has the new idle settings applied:

Analyzing the PowerShell Script
This script begins exactly how our previous script began for enabling/disabling a desktop group.

The Get-XdDesktopGroup cmdlet is used to get a reference to an existing desktop group. This cmdlet returns a XdDesktopGroup object which we are storing into a variable called $xdgroup. We are passing two parameters to the Get-XdDesktopGroup cmdlet (the name of the desktop group we want to get and the DDC address so the script knows where to look for it). We are also passing an additional flag called -HostingDetails. The hosting details flag allows you to retrieve the Virtual Machine name for each of the virtual desktops in the desktop group as part of the returned object. With this flag included, you get both the Active Directory machine name and Virtual Machine name for each virtual desktop in the group. Without this flag, the Get-XdDesktopGroup cmdlet would just return the Active Directory machine name for each virtual desktop within the desktop group.

The $xdgroup variable is an object of type XdDesktopGroup. This object has a property called HostingSettings which is an object itself of type XdGroupHostingSettings. How did we know that? That’s where the get-member cmdlet comes in. We mentioned this cmdlet in many of the previous blogs in this series and is a must to understand if you want to develop these types of scripts on your own. In fact, when you are starting out with the SDK and running this script for the first time, I would recommend executing the following commands once you get your $xdgroup variable defined.

#Display the current contents of the $xdgroup variable
echo $xdgroup

#List all the properties and methods supported by the XdDesktopGroup object
$xdgroup | get-member

#Display the current contents of the $xdgroup.hostingsettings property
echo $xdgroup.hostingsettings

#List all the properties and methods supported by the XdGroupHostingSettings object
$xdgroup.hostingsettings | get-member

The PowerShell script then sets several of the idle pool settings of $xdgroup.HostingSettings property. You’ll notice that some of these settings are numbers (OutOfHoursIdleCount, BusinessHoursIdleCount, PeakHoursIdleCount), some represent a TimeSpan (PeakHoursStart, PeakHoursEnd, BusinessHoursEnd), one represents a TimeZoneInfo object (IdleTimesTimeZone), and one represents a collection (BusinessDays). The BusinessDays collection represents which days are to be considered “business days” for the desktop group. When you create a new desktop group, this collection contains Monday through Friday by default. In our example here, we also had Saturday and Sunday in the collection and we were removing them as part of this script. You can Add and Remove any of the days from the collection as you see fit. For example, you may have a Tuesday through Saturday schedule and need to update the BusinessDays collection to reflect that.

Finally, to commit the change back to the Desktop Delivery Controller, you use the Set-XdDesktopGroup cmdlet.

Wrap-up
This article explains how to update the idle pool settings of a desktop group via a PowerShell script. At various times throughout the year, you may see shifts in load and want to provide the most optimal number of idle sessions to handle them. This might mean increasing the idle counts for the busier seasons and decreasing the idle counts for the slower seasons. The adjustment of the idle pool count can be automated via the PowerShell script sample shown within this blog.

In the next blog, we will look at adding new virtual desktops to an existing desktop group via PowerShell script. Stay tuned!

Upcoming TechTalk
I will be leading a TechTalk with Mike Bogobowicz on Essentials for using Windows PowerShell with XenApp and XenDesktop on Tuesday, August 24 from 2pm to 3pm EST. If you interesting in learning more about these SDKs first hand and want to see the demos in action, you can sign up here. We hope to see you there!

Blogs in this series

Ed York – Senior Architect – Worldwide Technical Readiness
Ask-the-Architect Site: http://community.citrix.com/p/product-automation#home
Follow Me on twitter: http://twitter.com/citrixedy