Forum Discussion
Office 365 license consumption alert
- Mar 23, 2017
In terms of alerts, no. A quick glance at the Admin portal or the Reports can give you this info. If you need it automated it really takes few lines of PowerShell code to check for available licenses and fire up an email notification.
Hi everyone,
even if this threat appears to be stuck or dead - I would be very interested to get the powershell code for getting alerts on low license counts - based on comparision of purchased and assigned licenses directly on the tenant level.
Would be very appreciated.
best regards
Markus
It takes two lines of PowerShell, and you have all the building blocks in the replies above.
- Markus KalmbachMar 01, 2018Copper Contributor
Hi Vasil,
thank you for the reply. The parts I can find above are how to send mails via powershell - got that, no issue.
I want to go straight to the available license information within the Admin Center -NOT- exporting all licensed users, counting them, storing in a file / variable looping through E1 and E3 users, and then compare it against the SUM of available licenses in the tenant.
I just want to get the latest part done - get the amount of purchased licenses from the tenant. Do you have an hint, how to get this information direct?
best regards
Markus
- Markus KalmbachMar 01, 2018Copper Contributor
I´d like to share it with you - I found the right Cmdlet: Get-MsolAccountSku
gives you the overall figures I was searching for:
AccountSkuId ActiveUnits WarningUnits ConsumedUnits
------------ ----------- ------------ -------------
p3group:STREAM 1000000 0 65so this will be the basis for our alarming script of low license counts. not the powershell folks can step in :-)
https://docs.microsoft.com/en-us/office365/enterprise/powershell/view-account-license-and-service-details-with-office-365-powershell
- Joel HazeltonApr 12, 2018Copper Contributor
#Set the license variable
$License = Get-MsolAccountSku | Where-Object {$_.accountskuid -eq "<YourAccountSkuid>"}
#Calculate available licenses
$FreeLicense = $License.ActiveUnits - $License.ConsumedUnits#If fewer than <some number> available licenses, execute the rest of the script
If ($FreeLicense -lt <some number>){
#Do something. I have the script run then a report of all terminated users that still hold onto a license, based on license info in Msol and deactivation date in Active Directory (our termed users are deactivated in AD then removed after 30 days). Report also includes the day that the license will be freed up (i.e. when the termed/deactivated account will be fully removed). Report is then emailed to O365 admin team.
}
My only problem is figuring out how to truly store the password securely, in order to run this script as a scheduled task. Theoretically, if a password is stored as an encrypted string in PowerShell, couldn't anyone who gains access to the server on which the script runs then use those secure credentials to run other malicious scripts? I'm relatively new to PS so I don't yet understand all concepts.
- VasilMichevMar 01, 2018MVP
I'm not sure what you mean, you mentioned PowerShell alerts above? There is no need to loop over each user in order to "count" the licenses, the Get-MsolAccountSku cmdlets will show you the "total" and "assigned" numbers. If you want to get those from the portal, you can use the overview at: https://portal.office.com/adminportal/home#/setupproducts