Find Office 365 Users with a given license
The Goal
Find all the Office 365 users with a given license
The Solution
First we need to connect to Office 365 using power shell
Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService –Credential $cred
Use Get-MsolAccountSku
to find a specific SKU, in this example we are going to use tenent:O365_BUSINESS_PREMIUM
$users = Get-MsolUser -All | ?{ $_.isLicensed -eq "TRUE" }
$sku = "tenent:SMB_BUSINESS_PREMIUM"
$users | ?{ ($_.Licenses | ?{ $_.AccountSkuId -eq $sku}).Length -gt 0}