This script will help to keep track of how many licenses are left and based on that you can take decision to procure more.

  • You need global admin rights to run this script.
  • Identify, which license need to be tracked and how much buffer you need before an email will be sent.
  • Keep note of AccountSkuIdusing via Get-MsolAccountSku and replace them in below script.
$AccountSkuId = "learntechfuture:ENTERPRISEPACK"
$AdminUsername = "globaladmin"
$AdminPassword = "credentialhere"
$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AdminUsername,$SecurePassword
Connect-MSOLService -Credential $cred

function get-visiolicense{
$skuVisio = Get-MsolAccountSku | Where-Object {($_.accountskuid -eq "learntechfuture:VISIOCLIENT")}
$skuVisioactive = $skuVisio | select activeunits
$skuVisioconsumed = $skuVisio | select consumedunits
$skuVisioactiveLeft = ($skuVisioactive.activeunits - $skuVisioconsumed.consumedunits)
$skuVisioadd3 = $skuVisioconsumed.ConsumedUnits + 2
if ($skuVisioadd3 -gt $skuVisioactive.ActiveUnits)
{
#	write-host Purchase more Visio Online P2 Licenses because only $skuVisioactiveLeft Left, We keep 2 licenses in buffer.
Send-MailMessage -SmtpServer smtp.learntechfutre.com -To 'sourabh.jha@learntechfutre.com' -From LicenseAlert@learntechfutre.com -Body "Purchase more Visio Online P2 Licenses because only $skuVisioactiveLeft Left, We keep 2 licenses in buffer." -Subject "Attention : Purchase Visio Online P2 License, $skuVisioactiveLeft Left."
}
}
function get-ExchP1{
$skuExP1 = Get-MsolAccountSku | Where-Object {($_.accountskuid -eq "learntechfuture:EXCHANGESTANDARD")}
$skuExP1active = $skuExP1 | select activeunits
$skuExP1consumed = $skuExP1 | select consumedunits
$skuExP1activeLeft = ($skuExP1active.activeunits - $skuExP1consumed.consumedunits)
$skuExP1add3 = $skuExP1consumed.ConsumedUnits + 10
if ($skuExP1add3 -gt $skuExP1active.ActiveUnits)
{
	write-host Purchase more Exchange Online P1 Licenses because only $skuExP1activeLeft Left, We keep 25 licenses in buffer.
Send-MailMessage -SmtpServer smtp.learntechfutre.com -To 'sourabh.jha@learntechfutre.com' -From LicenseAlert@learntechfutre.com -Body "Purchase more  Exchange Online P1 Licenses because only $skuExP1activeLeft Left, We keep 25 licenses in buffer." -Subject "Attention : Purchase Exchange Online P1 License, $skuExP1activeLeft Left."
}
}
function get-E3{
$skuE3 = Get-MsolAccountSku | Where-Object {($_.accountskuid -eq "learntechfuture:ENTERPRISEPACK")}
$skuE3active = $skuE3 | select activeunits
$skuE3consumed = $skuE3 | select consumedunits
$skuE3activeLeft = ($skuE3active.activeunits - $skuE3consumed.consumedunits)
$skuE3add3 = $skuE3consumed.ConsumedUnits + 10
if ($skuE3add3 -gt $skuE3active.ActiveUnits)
{
#	write-host Purchase more Office Enterprise E3 Licenses because only $skuE3activeLeft Left, We keep 25 licenses in buffer.
Send-MailMessage -SmtpServer smtp.learntechfutre.com -To 'sourabh.jha@learntechfutre.com' -From LicenseAlert@learntechfutre.com -Body "Purchase more Office Enterprise E3 Licenses because only $skuE3activeLeft Left, We keep 25 licenses in buffer." -Subject "Attention : Purchase Office Enterprise E3 License, $skuE3activeLeft Left."
}
}
function get-ExchP2{
$ExchP2 = Get-MsolAccountSku | Where-Object {($_.accountskuid -eq "learntechfuture:EXCHANGEENTERPRISE")}
$ExchP2active = $ExchP2 | select activeunits
$ExchP2consumed = $ExchP2 | select consumedunits
$ExchP2activeLeft = ($ExchP2active.activeunits - $ExchP2consumed.consumedunits)
$ExchP2add3 = $ExchP2consumed.ConsumedUnits + 10
if ($ExchP2add3 -gt $ExchP2active.ActiveUnits)
{
	#write-host Purchase more Exchange Online P2 Licenses because only $ExchP2activeLeft Left, We keep 10 licenses in buffer.
	Send-MailMessage -SmtpServer smtp.learntechfutre.com -To 'sourabh.jha@learntechfutre.com' -From LicenseAlert@learntechfutre.com -Body "Purchase more Exchange Online P2 Licenses because only $ExchP2activeLeft Left, We keep 10 licenses in buffer." -Subject "Attention : Purchase Exchange Online P2 License, $ExchP2activeLeft Left."
}
}
get-visiolicense
get-ExchP1
get-E3
get-ExchP2

Thank you for reading

Advertisement