Office 365 License check + notification script

I think we all have had a moment where we wanted to create a new user account but the licenses for Office 365 had run out. Our Sysadmins asked me to write a script which would send an e-mail if the licenses almost would run out.

I would run the script from a management server which is able to send e-mail via an Exchange server or similar relay server. Furthermore the user that runs the script doesn’t need admin permissions in Office 365. You can just create a regular user account to run the script. To check whether your user account has the right permissions do the following.

Log on to Microsoft 365 Powershell via the following command:

Then run the following command:

You will see something like:

You will probably see more output because you have more licenses activated. Everything after “:”, in the example “SPE_E5”, is the official microsoft licensename. For Office 365 E3 it’s tenantname:ENTERPRISEPACK.

In the following example the licenses for Office 365 E3 and EMS E3 are checked and if there are less then 3 available an e-mail will be send. Check it out:

If you have any questions don’t hesitate to ask.

Regards

Niels

Related Posts

Leave a Reply