SOLVED

Office 365 license consumption alert

Brass Contributor

Hi,

 

Does Microsoft provides any alerting on the case that availabe licenses to assign are\near to be 0?

 

I already see that several blogs provide details for creating your own alerting\report for license consumption using powershell, but I'm interested to confirm if Microsoft has something out of the box.

 

Regards.

23 Replies
best response confirmed by Carlos Gomez (Brass Contributor)
Solution

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.

I was wondering if someone has got that Powershell code for viewing license and setting up for email notification. 

 

I know how to view license  (Get-MsolUser -UserPrincipalName belindan@litwareinc.com).Licenses.ServiceStatus  - how do i add this to a notification email.

 

Thanks

Sending messages via PowerShell is very easy. Get the information you want via the licensing cmdlets, then simply use something like:

 

$body = "blabla you have $somevariable available licenses out of $anothervariable blabla"

 

Send-MailMessage -SmtpServer outlook.office365.com -To user@domain.com -From you@domain.com -Subject "Free licenses report" -Body $body -BodyAsHtml -UseSSL -Credential (Get-Credential)

 

Of course if you aim to automate it you can use a different account, store the credentials securely and reuse them. You can also use your own SMTP server instead of O365 ones, etc.

Hi Vasil,

 

Do you know if there is a way to schedule the reports to be send? instead of going every day to open the admin portal and look for the report.

 

Regards. 

Unfortunately no, only few reports have the schedule functionality (the EOP related ones).

Thanks Vasil much appreciated 

If you go the PowerShell route and want a schedule report you can always set it up on a server to run as a schedule task on a recurring basis. I've done a few reporting solutions this way to achieve a scheduled report :)

Must probably we will use this way, but would be nice if microsoft provides this out of the Box.

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.

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

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

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            65

so 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-de...

#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. 

This issue, the lack of an Office 365 license consumption alert, is still unresolved (06/22/2018). 

There is a feedback forum post for the task; Azure AD feedback: Get 'low license count' notification 

Please vote it up if you really want to see the change. 

 

And as others have noted, you can set up a scheduled task to PowerShell an email to your relevant crew who may see going to the portal as an inconvenience. 

I included my script below with <descriptions> of items that need filled in. 

If you need help getting keys and such to encrypt passwords, try Share-gate or KeePass who provide good MS Online compatible encryption tools. 

 

# 
# Send_O365LicensingReport.ps1 
#

$key = (<integer array>); 
$secureString = "<encrypted Password>" 
$PWord = ConvertTo-SecureString $secureString -key $key; 
$User = "<GlobalAdmin>@<company domain or .microsoftonline.com>"; 
$Credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $User, $PWord

#Get the Office365 tenant credentials 
$Office365credentials = Get-Credential $Credential;

Connect-MsolService -Credential $Office365credentials; 
write-host "Connecting to Microsoft SharePoint Online Service ..."

[String]$SkuReport1 = Get-msolAccountSku | Select @{N='Product Name';E={switch ($_.AccountSkuId) { '<company domain>:ENTERPRISEPREMIUM' {'Office 365 Enterprise E5'} '<company domain>:POWER_BI_PRO' {'Power BI Pro'} '<company domain>:ENTERPRISEPACK' {'Office 365 Enterprise E3'} '<company domain>:SHAREPOINTSTORAGE' {'SharePoint Online Storage'} '<company domain>:POWER_BI_STANDARD' {'Power BI (free)'} '<company domain>:EMS' {'Enterprise Mobility + Security E3'} '<company domain>:MCOMEETADV' {'Audio Conferencing'} '<company domain>:DYN365_ENTERPRISE_SALES' {'Dynamics 365 for Sales Enterprise Edition'} '<company domain>:DYN365_ENTERPRISE_TEAM_MEMBERS' {'Dynamics 365 for Team Members Enterprise Edition'} default {'Unknown'} }}}, @{N='Active Units';E={$_.ActiveUnits}}, @{N='Consumed Units';E={$_.ConsumedUnits}}, @{Name = 'RemainingUnits'; Expression = {[string]([int]( $_.ActiveUnits - $_.ConsumedUnits))}}, @{N='Account SkuId'; E={$_.AccountSkuId}} | ConvertTo-Html

Send-MailMessage -SmtpServer mail.<company domain> -To <recipient>@<company domain> -From <sender>@<company domain> -Subject "Consumed licenses report" -Body $SkuReport1 -BodyAsHtml

 

 

A daily report via PowerShell is nice, but even better is an alert when certain numbers are hit based on previous reports! E.g. 0 remaining or 1 remaining.

@Carlos Gomez, this is probably coming late. Just thought I should share this should anyone else needs it. https://insterswap.wordpress.com/2020/03/29/automatically-alert-your-team-when-your-tenant-is-runnin...

Depending on how big or complicated your environment is, the alert script may require a little modification. Our need was just as simple as “tell us when our license is low or out”. As the saying goes, necessity is the mother of invention. Feel free to modify the script.

@Carlos Gomez 

 

Its not pretty but this will do what you want.  I have configured it for SPE_E3 sku but you can change it for which ever license type you want in the variables.  it will send an email when there are 10 licenses left.  Keep in mind if you use 10 licenses in between the script run cycles you might get notified too late. 

 

$sku =Get-MsolAccountSku | where accountskuid -EQ "tennant:SPE_E3"
$skuactive=$sku | select activeunits
$skuconsumed=$sku | select consumedunits
$skuadd10 = $skuconsumed.ConsumedUnits +10
if ($skuadd10 -ge $skuactive.ActiveUnits) {Send-MailMessage -SmtpServer smtpserver01 -To geeman@maildomain.com -From geeman@maildomain.com -Body test -Subject test }

1 best response

Accepted Solutions
best response confirmed by Carlos Gomez (Brass Contributor)
Solution

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.

View solution in original post