For the last several years, I’ve had the honor and privilege of working closely with a colleague of mine, Bryan Zanoli. Bryan is incredibly sharp in the ways of Citrix, Microsoft and VMware virtualization and it’s been awesome working so closely together watching him hone his craft. Bryan recently embarked on a pet project to retrieve EdgeSight like reports (for you old-timers) from the Citrix Monitoring database (XenApp/XenDesktop 7.x). Some of these reports would show login times, durations, and usernames to be used for internal usage accounting. Bryan volunteered to share some of his key findings in his first guest blog post. If you have content you would like to contribute and be a guest blogger (or regular) on itvce.com, feel free to reach out to me at dane@itvce.com or on Twitter @youngtech so we can discuss. Without further ado, below is the guest blog post by Bryan Zanoli, you can find him on LinkedIn or on Twitter.

I recently pursued a way to programmatically track certain Citrix events through PowerShell. What I discovered proved very insightful and will hopefully provide you with additional tools for easier tracking, custom reporting, and automation in a Citrix XenApp/XenDesktop 7.x enviornment.

Getting Started with Citrix Monitoring

Before I continue, please see the following article by Dana Gutride, XenDesktop 7 Monitor Service – What Data is Available? In it you will find reference to the Citrix Monitoring service OData API. With the XML manipulation power of PowerShell, this data can be captured and leveraged to perform incredible tasks, such as determining which users logged on, how often, on a given date or time.

Another item to note: Citrix monitoring data is captured in the database for a period of time based on both licensing and XenDesktop site configuration. Retaining data for longer than 7 days requires XenApp or XenDesktop Platinum, and can be configured using the Set-MonitorConfiguration cmdlet. Platinum licensing offers 90 days of data retention by default but can be extended to a full year. Additional details can be found in this Citrix white paper here.

Building the Script

To view the available data, navigate to http://localhost/Citrix/Monitor/Odata/v1/Data, where “localhost” is the Fully Qualified Domain Name of your Delivery Controller.You will need to disable RSS Feed View if using Internet Explorer. When properly displayed you will see what looks like XML data. Using PowerShell, we can save this data, based on which object we wish to manipulate or capture.

To demonstrate, I’ll run through the process of obtaining session data and filter the data based on date.

Here we receive the same output as above for $sessions.Content.Properties, but only for sessions, which start date was February 05, 2015:

Now that you have been introduced to working with Citrix Monitoring data, review the script at the end of the blog to see how I managed to create a script that returns the username and logon count for a specified date. This is accomplished by taking the UserId from the session data and grabbing the corresponding username from that UserId:

$userIDs = $sessionDate.UserId.InnerText

We now have a list of UserIds:

We can take this list of UserIds and run it through a for-loop to grab the username for each UserId:

This will the username for each session, but there has got to be a better way to keep track of logon count:

So as to not spoil all the fun, I’ll offer the final running of the complete script as an exercise for the reader.

I’ll leave you with a possible use case. Imagine a service provider that is creating a charge back model in which they charge per hour or day as each user accesses an environment. With some slight modifications, the script could be made to run weekly or monthly and output the total hour or total day counts for each user. Modify the output so that it works with existing financial software, and the service provider now has a fully automated billing process!

The sky is the limit with the ability to easily extract the Citrix Monitoring data with PowerShell. These exact concepts could also be used to create a script that dynamically deploys or removes Virtual Desktops based on the number of users logging in each day!

What tasks could you accomplish with Citrix Monitoring data in the hands of PowerShell?