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!

Kelvin Tegelaar
Follow me

4 thoughts on “Monitoring with PowerShell: Monitoring RDS UPD size

  1. Dash

    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.

    Regards
    Dash

    Reply
    1. Kelvin Tegelaar Post author

      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. 🙂

      Reply
  2. Matt

    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?

    Reply
    1. Kelvin Tegelaar Post author

      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. 🙂

      Reply

Leave a Reply

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.