Category Archives: General

Get VMware Unified Access Gateway (UAG) Session Count Using PowerShell

With the recent COVID-19 catastrophe, we had the need to automatically pull UAG session statistics and report them to a dashboard so we could keep track of our external Horizon users to ensure the 2k limit per UAG was not exceeded. What better way to automate this than a little PowerShell?

VMware has some documentation on the API URL and definitions here – unfortunately there’s no information on how to interact with the API, authenticate, etc., so I had to figure that out for myself. Special thanks to pallabpain for the great REST framework that I used for this script – I will certainly continue to utilize it!

I recommend creating a read-only account in the GUI under Advanced Settings -> Account Settings. Definitely no reason to use your production admin account for this:

Here’s the full script – you just need to paste it into a .ps1, execute it, and it will become an available function:

# This is a script to grab UAG authenticated sessions
# Written by Nick Burton

# Ignore cert errors

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'

# Create a function for UAG API call - thanks to for this great REST framework!

function Get-UAGSessionCount([string]$username, [string]$password, [string]$UAGHostName) {
  $url = "https://"+$UAGHostName+":9443/rest/v1/monitor/stats"
  # Step 1. Create a username:password pair
  $credPair = "$($username):$($password)"
  # Step 2. Encode the pair to Base64 string
  $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
  # Step 3. Form the header and add the Authorization attribute to it
  $headers = @{ Authorization = "Basic $encodedCredentials" }
  # Step 4. Make the GET request
  $responseData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers -UseBasicParsing

  $firstString = "<authenticatedSessionCount>"
  $secondString = "</authenticatedSessionCount>"
  $content = $responseData

  # Get the value between the two strings above
    $pattern = "$firstString(.*?)$secondString"

    # Output result of pattern match using regex
    $result = [regex]::Match($content,$pattern).Groups[1].Value

    # Return result
    return $result

Execute it with PowerShell, and you now have an available PowerShell function called Get-UAGSessionCount:

Get-UAGSessionCount -username [read-only UAG account] -password [password] -UAGHostName [FQDN or IP of UAG]

After executing, you’ll simply get a number back. This number represents the AuthenticatedSession count found in the UAG GUI:

With this, you can do some pretty cool stuff. Add it to a scheduled task that outputs the value to a csv with the date/time. Use it in PowerBI, Tableau, etc. across your UAG’s to have a real-time dashboard of your remote workforce. Happy monitoring!

Citrix Personal vDisks

Citrix PvD (or Personal vDisk) is a great way to allow users to have the freedom of installing their own applications and customizations, while still having the standard vDisk as its base disk. Citrix has made major improvements to this architecture throughout the years. The personal vDisk is a virtual disk that you will actually attach to your virtual machine where the user’s read/writes will go (in order for the changes to persist upon logon/logoff). XenDesktop will magically “merge” the base and PvD in order to reflect version changes, etc.

One of the main problems that users will run into is when they run out of storage of their PvD. This will prevent the user from installing applications, etc., and of course, you, as the Citrix admin, will be responsible for fixing it. This article will  be written assuming you are using an ESXi/vSphere environment, but this will pertain to any virtual environment (Hyper-V, XenServer)

There are a couple of basic things you should know about PvD customizations. The settings are contained within HKLM > SOFTWARE >  Citrix > personal vDisk > Config. You can change these settings by simply creating a new version on the golden image. The main setting you will want to tweak is “PercentOfPvDForApps.”

For whatever reason, Citrix defaulted this to 50/50. This means that if you provide a user with a 60GB PvD (we’ll use this number for the rest of the article), 30GB will be used for application installs, and 30GB will be used for the user’s profile. This could be overkill for the profile, especially if you are using profile management. So make sure and adjust this setting to best suit your environment.

Another thing you should know is that (by default) the user will see 2 drives – the C and P drive. The P drive is actually the whole 60GB VMDK you attached for the PvD. The C drive is a hidden VHD contained within the P drive, which represents the thick provisioned app percentage that you specified in the registry! So C = P * PercentOfPvDForApps(%)

Hidden VHD in the vDisk
Hidden VHD in the vDisk

From what I understand – the UserData.v2.vhd.thick_provision is essentially the initial thick reserved app space, while any future expansions go to the UserData.V2.vhd thin provisioned VHD.

So, that’s some basics of personal vDisks in MCS or PVS. I am also going to go ahead and write about a specific scenario I ran into while expanding a user’s vDisk:

As I talked about before, expanding a vDisk is really easy. Simply expand the VMDK in vSphere console, partition it out using disk manager in Windows, shut down the user’s machine, start it up, and Citrix will automagically expand out the C:\ drive based on the PercentOfPvDForApps in the registry.

Well, I ran into a user who had about 11% of his C:\ drive remaining, and it refused to expand, even when I expanded his personal vDisk VMDK. His applications were failing to install because he did not have sufficient disk space. I was baffled!

I happened to stumble across an article that said the user’s C:\ drive portion would not expand unless it had less than 10% remaining (just my luck, the user had around 11%). So I moved an application folder over to his C:\ drive just to eat up space, restarted his VM, and bam! The C:\ drive expanded to the percentage I had expected.

Hopefully this article helped you understand a little bit about how personal vDisks operate, and I hope that the scenario helps someone as unlucky as me out there. Enjoy!!


Hey everybody! My name is Nick Burton and this is my first IT blog; well, my first blog ever! I’m extremely excited to get this started, as I have been meaning to do it for quite some time.

Throughout the years of my professional IT experience, I have ran into many issues that are undocumented or poorly documented by the product vendors; ranging from Office 365 down to the nitty gritty of Citrix Provisioning Services. I hope to get at least one blog post a week so that I can share some unique tips and tricks for different scenarios. I also am going to try to post at least once a month about a cool technology that I would like to share with the world, including general (and unbiased) ratings for the product.

Feel free to check out my About Me page to learn a little bit more about my background. I hope you all enjoy!