M365 License Usage Notification - mattnovitsch/M365 GitHub Wiki

Summary:

      I had a request from a customer to get notifications on when they were running out of licenses. They wanted to know when they were at 90% usage so they could acquire additional licenses or clean up some. I was able to search for a Power Automate report that does this from Jan Bakker from the Netherlands (link in the reference section). I was able to get it setup in my lab in a couple of hours and wanted to create an export for it for easier redistribution and some modifications to what was added to his.

Reference:

Prerequisites

Steps to install:


1. Login to https://Portal.Azure.com
2. Navigate to App Registration



3. Click On New registration



4. Give your application a name, I am naming mine License Reporting. You can change who can use the API to whatever option you like and change it later if you desire. Leaving it at default is how I set mine up in my lab. Click Register to complete the application registration process.



5. Click your application, it should look something like this:



6. We must create a secret for the application (think of it as a token)



7. Click new client secret.



8. Add a description and change the expiration date as needed, I put in LicenseReport for the description and left the expiration default.



9. Copy the secret value, save it into a notepad or WordPad something where you can retrieve it later. (red square with an arrow pointing to it.)



10. Navigate to API Permissions on the left.



11. Click Microsoft Graph.



12. Filter on “organization”. Expand Organization at the bottom and check Organization.Read.All. Click "Update Permissions" to complete.



13. Grant admin consent for your environment.



14. Click on Overview. Copy Client ID and Tenant ID to notepad or WordPad as well.


15. Navigate to https://us.flow.microsoft.com/ to import the Power Automate workflow.
16. Click My flows on the left side.



17. Click Import at the top.



18. Click Upload.



19. Navigate to where you have downloaded Licenseusagereport.zip.



20. Click the configure wrench (red square) under the Flow resource type.



21. Change the Setup from “update” to “Create as new”. Click save to complete the update to import setup.



22. Click the configure wrench (red square) under the Mail Connection resource type.



23. Click Create New.



24. Click create a connection.



25. Type “mail” in the top right corner search box. Then click the + to add the Mail connector.



26. Click Accept and create button.



27. Close the tab once the Mail connector is created. You should see the Mail Resource on the Import Setup screen now. Click Save to continue.



28. Click import to complete the import process.



29. Click Open Flow once the import has successfully imported.



30. You can change the recurrence from 1 day to whatever you desire. This is done by selecting the Recurrence action on the top of the flow.



31. Get your notepad or WordPad ready, this is where we need those IDs. Open the HTTP action, click on “Show advance Options”. Replace the word TenantID with your TenantID number, ClientID with your client number, and SecretPassword with your Secret password.



32. Change the condition to meet your company’s requirements. Right now, its setup for 10% so I could trigger it in my lab. If you want daily emails, then 10% would be fine. If you want to know when you are 75% then just change it to 75. Scroll down to Apply to each > Condition then change the 10 to your desire configuration. You could also delete percentage and use totals also, that would be completely up to your company. This template is just for percentage.



33. The last thing we need to change is the email address this is going to. Right now, its setup to go to [email protected]. You will need to change it to a distribution list or person(s) you want to get this notification. Please note that there limits to the number of emails that can be sent. Mail Connector - Throttling Limits



34. Please remember to Save it. Top right corner.



35. Click “Turn on” in the action bar.



NOTE: Due to replication between the AAD and Power Automate permissions for the API could take several hours to complete. You might see errors that say you have insufficient privileges.


36. Once complete you should start getting emails like this:



⚠️ **GitHub.com Fallback** ⚠️