Making sure your Citrix Desktops are utilized in 35 lines of PoSH

Earlposhier this week one of our SEs asked the following question on an internal Slack channel: “I have a customer that is looking for an automated process to identify VDI VMs that haven’t been used, notify the users, and then ultimately reclaim them if noone has logged on in a certain amount of time”. 

 

PoSH time! One of my first go-to’s was ‘Get-ADComputer and use the ‘LastLogonDate‘ but after fiddling around a bit I noticed that the ‘Get-BrokerDesktop‘ has a value for ‘LastConnectionTime‘ which actually makes more sense as this is the path a regular user would take vs an admin that can login to a desktop via the console and thus creating false positives.

The first piece was pretty straightforward:

I had to use the Office 365 SMTP servers hence why you’d see the additional parameters for SSL, Creds and ports. This might be different for your own environment, also you need to make sure that the account you’re using to send the email has send-as rights for the alias you’re using for the -from parameter. This piece of script fetches all assigned desktops in a XD site, determines the last logon time and if it’s longer than 30 days it will collect the user assigned to the desktop all while utilizing posh cmdlets. Based on the user AD will be queried and the email address will be fetched to send out an email. So far, so good.. Result!

PoSH

I’ll be working on the second part of automatically reclaiming the desktops after x period of time when time allows me. For now I got what I wanted, happy scripting!

The following two tabs change content below.

Kees Baggerman

Kees Baggerman is a Staff Solutions Architect for End User Computing at Nutanix. Kees has driven numerous Microsoft and Citrix, and RES infrastructures functional/technical designs, migrations, implementations engagements over the years.

2 comments

  1. […] on May 10, 2017 submitted by /u/kabanossi [link] [comments] Leave a […]

  2. […] my post from April on Making sure your Citrix Desktops are utilized in 35 lines of PoSH I mentioned I would be looking to expand the powershell script and I’ve added just a few […]

Leave a Reply

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