Monitoring with PowerShell: Monitoring RDS UPD size

So our clients have RDS deployment, WVD deployments, and just in general VDI-like environments. To make sure their profile can be loaded on each machine without having to set everything up again we use UPDs.

Of course these UDP’s have a maximum size defined and need to be monitored, you can monitor the location where you host your UDP’s but that is not enough. The disk could reach a maximum size without running out of disk space on the shared location.

You can use the following script to monitor the RDS UPD size, measured against the disks own maximum size. This script only works for disks that are currently mounted – So the user has be logged in to monitor the disk size.

UPD Monitor script

$DisksInWarning = @()
$VHDS = get-disk | Where-Object {$_.Location -match "VHD"}
foreach($VHD in $VHDS){
$Volume = $VHD | Get-Partition | Get-Volume
if($Volume.SizeRemaining -lt $volume.Size * 0.10 ){ $DisksInWarning += "$($Volume.friendlyname) Less than 10% remaining"}

This script will alert when we have less than 10% available. Now the downside of using this script is that it only states the friendly name of the disk that is in warning. In the case of UPDs this is often a long SID or a generic name. So to make sure this is actually useful we’re also going to retrieve the SID of the users, and translate these to the username.

$DisksInWarning = @()
$VHDS = get-disk | Where-Object {$_.Location -match "VHD"}
foreach($VHD in $VHDS){
$FilePath = [io.path]::GetFileNameWithoutExtension("$($VHD.Location)")
$SIDObject = New-Object System.Security.Principal.SecurityIdentifier ($FilePath) 
$Username = $SIDObject.Translate([System.Security.Principal.NTAccount])
$Volume = $VHD | Get-Partition | Get-Volume
if($Volume.SizeRemaining -lt $volume.Size * 0.10 ){ $DisksInWarning += "$($Username.Value) UPD Less than 10% remaining. Path: $($VHD.Location)"}

And that’s it! as always, Happy PowerShelling!


  1. Dash May 14, 2020 at 5:40 pm

    Hi Kel Vin

    Have you got the complete script? I am looking for Powershell reporting script when each users UPD’s approaching capacity (5GB) and get an email notification with the user name.
    Please advice me.
    Thank you.


    1. Kelvin Tegelaar May 14, 2020 at 6:10 pm

      Hi Dash,

      This is the full script, but designed to run from your RMM system. You could add logic to e-mail to, but that is really out of scope for this blog. 🙂

  2. Matt May 15, 2020 at 2:09 am

    Hi Kelvin,

    Thanks for posting this up. I’m looking into this same issue at the moment but unfortunately I’m hitting a wall.
    I found with your script that I wasn’t getting any results with get-disk until I changed it to:
    $VHDS = get-disk | Where-Object {$_.Location -like “UVHD”}

    That populated my variable with a list of mounted VHDs. But I’m not getting any results. Even when I change the IF test to: -lt $Volume.Size * 1

    Any thoughts?

    1. Kelvin Tegelaar May 15, 2020 at 8:45 am

      Hi Matt,

      This doesn’t print anything to the console. the results are stored in the $DisksInWarning variable. you can add that variable to the bottom of the script if you want it printed. 🙂

  3. Jens Rüdiger May 29, 2020 at 12:51 pm

    Hi Kelvin,

    this script seems to be suitable only for VHD-files. Is it possible to have something similar for VHDX?


  4. Bryant Schaper November 3, 2020 at 8:08 pm

    Question: the vhds are dynamic in size, how do you account for the fact that say the file is 2GB in size but only really using 1GB from a user perspective?

  5. Alex August 2, 2021 at 11:35 pm

    Hi Kelvin,

    Great post.

    Have you tried this script on Windows 2012 R2? Get-diks returns a blank location, so I don’t have a way to identify the disk or match it to a user.

  6. Andrea August 25, 2021 at 9:39 am

    Hi Kelvin,
    i have executed your script on user session but it does not have permission:
    + CategoryInfo : PermissionDenied: (MSFT_Disk:ROOT/Microsoft/Windows/Storage/MSFT_Disk) [Get-Disk],


  7. YP December 8, 2021 at 8:55 pm

    Thanks, this script is great!
    Although, it initially did not work for me because my server names the UPD files “UVHD-“. I had to remove the “UVHD-” in line 5 by changing ($FilePath) to ($FilePath.substring(5))
    Hope to save someone else a lot of time banging their head adainst the wall.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.