Tuesday, March 13, 2012

Setting Peak and Off Peak Hours with PowerShell cmdlet Set-BrokerPowerTimeScheme in Citrix XenDesktop 5.5

As I noted in one of my previous posts:

Updating Citrix XenDesktop 5.5 desktop catalogs with PowerShell cmdlet

… navigating through the Desktop Studio can be a pain at times due to the responsiveness / wait times as you click through the menus and although I’m not sure if it is any faster if I was using XenServer as the hypervisor but it sure is slow when I’ve had to integrate it with VMware.  I find the response times especially annoying when I’m going through a deployment and need to configure multiple desktop catalogs then desktop groups and because I’m the type of person who doesn’t like to wait, I’ve been spending quite a bit of time looking into PowerShell cmdlets to see if there’s a way to cut down the amount of wait time and automate the process as much as possible.

One of the latest daunting task I’ve had to perform was to set the peak and off peak hours of multiple desktop groups and as intuitive as the GUI for the setting appears to be, I couldn’t stand have to click through so many items before I got to it:


After searching around the PowerShell cmdlets available for XenDesktop, I finally found that the cmdlet to set the peak and off peak hours was:


… and the cmdlet to get the current power scheme was:


What I quickly didn’t like about this cmdlet was how it displayed the PeakHours set for desktop group and the following is what the output looks like:

InputObject[0]: PS C:\Windows\system32> Get-BrokerPowerTimeScheme | format-list
name,desktopgroupuid,peakhours | fl

Name : VDI-Users_Weekdays
DesktopGroupUid : 1
PeakHours : {False, False, False, False...}

Name : VDI-Users_Weekend
DesktopGroupUid : 1
PeakHours : {False, False, False, False...}

Name : Win 7 Dedicated for VDI-Users_Weekdays
DesktopGroupUid : 3
PeakHours : {False, False, False, False...}

Name : Win 7 Dedicated for VDI-Users_Weekend
DesktopGroupUid : 3
PeakHours : {False, False, False, False...}

Name : Win XP for VDI-Users_Weekdays
DesktopGroupUid : 2
PeakHours : {False, False, False, False...}

Name : Win XP for VDI-Users_Weekend
DesktopGroupUid : 2
PeakHours : {False, False, False, False...}


Notice how the PeakHours value is truncated?  Before I go into what I don’t like about how it’s displayed, let’s first look at what the values presented mean.

The PeakHours of a desktop group is set via blocks of small green rectangles in the small horizontal bar in the GUI of the desktop group’s Power Management window.  Each small green block represents an hour during a 24 hour day and if you were to highlight the whole bar green as shown below, this would mean mean that all hours of your day will be set to peak hours:


With what the cmdlet return values and the GUI representation of the Peak Hours out of the way, what I immediately didn’t like about the values returned via PowerShell was that it was truncated and no matter what I tried (i.e. | FL for format list, piping to file), I couldn’t get the full value to get displayed (same with this other user I found who posted on the Citrix forums:  Furthermore, each true or false value represents an hour so if you wanted to set peak hours for the full 24 hours, you’ll need to essentially type or copy and paste 24 true(s) to set the peak hours.  In addition to the way the peak hours were set, I found that I really had to sit down and think about exactly which hour the first block represented.

Now that I’ve stated all of things I didn’t like about the cmdlet, let’s look at how I made it a bit easier for myself to set the peak hours for the desktop groups I had to configure.

First, you’ll need to values you’ll need to set the desktop groups you wanted to configure so begin by executing the following cmdlet to get the list of power scheme for all of your desktop groups:

Get-BrokerPowerTimeScheme | format-list name,desktopgroupuid,peakhours | fl

This will present you with the desktop groups and their respective weekday and weekend hours:


From the output presented to you, make a note of the following values for the desktop group you would like to modify:

  • name
  • desktopgroupuid

Once you have the value, proceed with using the Set-BrokerPowerTimeScheme cmdlet to set the peak hours:

Set-BrokerPowerTimeScheme -name VDI-Users_Weekdays -desktopgroupuid 1 -peakhours ($False,$False,$False,$False,$False,$False,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$True,$False)


This is definitely not an easy way to set the hours so what I ended doing was create a spreadsheet to map out the hours mapped to each block and simply used it to modify the settings as I wanted and then copied and pasted it out into the cmdlet:


What the spreadsheet above allows me to do is quickly change the cells’ value into either true or false depending on whether I wanted those hours to be peak or not then copy the column and then paste it at the end of the Set-BrokerPowerTimeScheme cmdlet to set the peak hours.

Note that I don’t live an breath in PowerShell which means that there may be an easier way to set the peak hours so if you’re someone who happens to come across this post and knows, feel free to comment below to share with the community.


Anonymous said...

Any idea how to change the weekend days itself. Ie. to have 1 day as the weekend.

Terence Luk said...

Interesting question. I don't think you can actually do that since it almost looks like weekends and weekdays are presets.