Query Terminal Server Sessions

I wanted a quick way to get a list of user sessions on our VDI servers.
My exact goal was to get a list of users that were a day away from being forced off the system and sending them an email.

TLDR: I ended up making this into a module: QuserObject.


Anyway, down to business.
We can use Quser to get the information.
Keep in mind that you can easily target a different computer: quser /SERVER:servername.

This is good information, but it would be so much better if it was an object.
Since it’s already a nice grid, let’s treat it as a CSV:

Beautifully simple, right?!
I originally posted this on stackoverflow because I just wanted a list of users.

Now, let’s get rid of that > on my entry, and fix those disconnected session columns.
This part gets a little more complicated.


Last things to do:

  • Change the idle . to a $null.
  • Type cast everything appropriately.
  • Change the property names to PascalCase.

Here’s the code for that:



I bit more complex, but still beautiful, right?
I’ll have to turn that into a module for ease of use.
I ended up making this into a module: QuserObject.

VertigoRay Administrator
Sorry! The Author has not filled his profile.

Leave a Reply

Your email address will not be published.