I recently recreated a PowerShell script for PRTG to monitor licensing assignments in Microsoft 365. Primarily I am concerned with Max Licenses and Assigned Licenses just to keep a steady on licensing from a production environment.
Drop the PowerShell script in the EXEXML folder on each PRTG probe.
In Azure Active Directory create a new App Registration.
Create a secret for the application registration for up to 2 years. Make sure you record your application secret in a password manager or you may have to regenerate it.
Add Application permisions for Directory.Read.All and Organization.Read.All. Grant admin consent for your tenant.
Go back to the overview to grab your Application ID. Store that in a password manager too.
Add an M365 Licensing device to PRTG. The IP address is meaningless to this deployment, but I like to keep it uniform with the tenant name.
On the M365 Licensing device, uncheck Inheritance. Fill in the tenant name for the domain or computername, the application ID for the username, and application secret for the password.
All sensors placed under this device will inherit these settings making sensor creation a bit easier.
In this example, I create a custom XML EXE sensor tracking the Developer E5 License given to most tenants created for educational purposes.
Scroll down to Sensor settings and select the PRTG-CheckM365Licensing.ps1 PowerShell script. Also provide the following parameters:
-username "%windowsuser" -password "%windowspassword" -hostname "%windowsdomain" -sku "DEVELOPERPACK_E5"
Manually refresh to double check that it is working. I would strongly encourage changing the scanning interval to something reasonable. I generally check every 6-24 hours on sensors of this nature.