Powershell Script: Alert via email if AD Group membership exceeded

For licensed software applications i have always used AD Security groups to manage license compliance, i create an AD Group for each piece of licensed software and set AD Description with the maximum amount of machines to be added.

Checking these groups manually for license compliance is tedious, so ive written the below script and placed it within a scheduled task to notify by email if groups exceed their count.