Get Office 365 users with a specific license type via PowerShell. Sometimes it is helpful to obtain a list of Office 365 users with a specific license type via PowerShell. There is no need to log into Office 365 portal and use a filtered view in the admin center. We can go straight into it from the command line.
In this post, we will be discussing how to get a list of users with a specific license type in Powershell.
What are Office 365 Licenses?
Office 365 Licenses are licenses that are specific to the Office 365 platform, they grant permission to various or specific Office 365 services. These varieties of Licensing Options provide Office 365 customers with the ability to pay for services as required.
In our article Get Office 365 users with a specific license type via PowerShell (Best Practices) we shall talk about creating reports with Office 365 via Powershell.
Create Report of Office 365 users with a specific License Type using PowerShell
We can generate a list of Office 365 users with a specific License Type from the Office 365 Administrator Portal but this will not be covered. Before we use PowerShell to generate this report, we will need to understand the following:
Product Name: This is the License name displayed in the Office 365 Administration Portal. Below is an image to explain it better:
String ID: This is the name or identifier that is used by Office 365 PowerShell v1.0 cmdlets when performing operations on Licenses, it is also known as the SkuPartNumber.
Below are the corresponding String IDs (SkuPartNumbers) for the Product Names in the image above:
Product Name
String ID
Azure Information Protection Premium P1
RIGHTSMANAGEMENT
Business Apps (free)
SMB_APPS
Dynamics 365 P1 Trial for Information Workers
DYN365_ENTERPRISE_P1_IW
Microsoft 365 E3
SPE_E3
Microsoft Dynamics AX7 User Trial
AX7_USER_TRIAL
Microsoft Power Automate Free
ERP_INSTANCE
Microsoft Teams Exploratory
TEAMS_EXPLORATORY
Power BI (free)
POWER_BI_STANDARD
Microsoft provides a table containing the majority of Office 365 Licenses with their Product Names, String IDs, GUID, Service Plan Names, Service Plan IDs and Service Plan Friendly Names.
Later in the article how to get Office 365 users with a specific license type via PowerShell , we will learn how to get the String IDs of the Licenses on the Office 365 tenant using PowerShell.
We will be making use of Windows Microsoft PowerShell and the MSOnline module which is known as the MSOnline V1 in PowerShell module for Azure Active Directory.
Getting a list of the current licenses on a Tenant
Some Administrators might want to get an overview and usage of the licenses or a list of license String IDs (SkuPartNumbers) on their Office Tenant before they run the report.
Below is a cmdlet that gives an overview and usage of the licenses on the Tenant:
# Returns an overview of license usage on the tenant
Get-MsolAccountSku
Below is a cmdlet that gives the list of the SKUs (String IDs) of licenses on the tenant
# Returns all the SKUs (String IDs) of licenses on the tenant
(Get-MsolAccountSku).SkuPartNumber
Exporting Office 365 Users with a specific license type to CSV using PowerShell
In this section how to Get Office 365 users with a specific license type via PowerShell is to create a report for Office 365 Users with a specific license type.
The report will have the following parameters in a CSV output file:
Below is the PowerShell script that generates this Office 365 Users CSV report:
Note: Change the $StringIDvariable in the PowerShell script to match the String ID of the license you which to run the report and also change the $ReportName variable to suit your desired output file path and file name.
The “.\” represents the present working directory (you can get this information by running the following cmdlets in your PowerShell session: PWD orGet-Location).
“.\” can be changed to any desired directory on the machine (E.g C:\Windows\)
# set the name of the report alongside the path ".\ relative path"
$ReportName = ".\Office365LicenseReport.csv"
# Set the String ID of the license ("SPE_E3" = Microsoft 365 E3)
$StringID = "SPE_E3"
# get all office Users
$UsersDetails = Get-MsolUser -All | Where-Object {($_.Licenses).AccountSkuId -match $StringID}
# set export array
$ExportArray = @()
# loop through each office 365 user with the specified String ID
Foreach ($UserDetail in $UsersDetails) {
# set the office 365 user's UserPrincipalName
$UserUpn = $UserDetail.UserPrincipalName.ToString()
# add values to array
$ExportArray += [PSCustomObject][Ordered]@{
# get the office 365 user's display name
"Display Name" = $UserDetail.DisplayName
# get the office 365 user's userprincipalname
"UserPrincipalName" = $UserUpn
# get the office 365 user's first Name
"First Name" = $UserDetail.FirstName
# get the office 365 user's last Name
"Last Name" = $UserDetail.LastName
# get the office 365 user's creation date
"When Created" = $UserDetail.WhenCreated
# get the office 365 user's mobile number
"Mobile Number" = $UserDetail.MobilePhone
# get the office 365 user's department
"Department" = $UserDetail.Department
# get the office 365 user's city
"City" = $UserDetail.City
# get the office 365 user's usage location
"Usage Location" = $UserDetail.UsageLocation
# get the office 365 user's mfa status
"MFA Status" = $UserDetail.StrongAuthenticationRequirements.state
# get the office 365 user's last password change timestamp
"Last Password Change Timestamp" = $UserDetail.LastPasswordChangeTimestamp
# get the office 365 user's block sign-in status
"Block Sign-In Status" = $UserDetail.BlockCredential
}
}
# echo the exported array
Write-Output $ExportArray
# export to csv file
$ExportArray | Export-Csv -Path $ReportName -Delimiter "," -NoTypeInformation
Great! We have learned about Get Office 365 users with a specific license type via PowerShell. We will summarize.
Get Office 365 users with a specific license type via PowerShell Conclusion
In this article, we discussed Office 365 Licenses and covered steps on how to generate a report of users with a specific license type. Check out our Office 365 reporting tool that allows you to easily create Office 365 license reports and automate these steps easily.
My background is in Cloud Operations, Office 365, Exchange Online, Security & Compliance, Active Directory and Dynamics 365 F&O. I'm a PowerShell Developer and ATTUNE Evangelist. Certified Cyber Security Professional (CSFPC).
3.52votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.