You should have the sign-in assistant and the Azure AD Module for Powershell already installed and be connected (connect-msolservice).
You’ll need to know what SKU you’re looking to check
Get-MsolAccountSku
I’ll be working with E1’s, and will throw it into a variable:
$accountsku = “megacorpinc:EXCHANGESTANDARD”
Once we have that, we’re ready to pull active and consumed units:
$activeunits = (Get-MsolAccountSku | where {$_.AccountSkuId -eq $accountsku}).ActiveUnits
$consumedunits = (Get-MsolAccountSku | where {$_.AccountSkuId -eq $accountsku}).ConsumedUnits
Then take the difference…
$availableunits = $activeunits – $consumedunits
And there you have it.