Friday, 16 March 2018

Find Office 365 users with a specific license type using PowerShell

We may fall in a situation to get a list of Office 365 users with a specific license plan to decide license usage or some other need. We can easily find users who has a specific office 365 license feature using Azure AD Powershell commands.

Before proceed, first run the below command to connect Azure AD Powershell module.
Import-Module MSOnline
We can run Get-MsolAccountSku cmdlet to get a list of the available licenses in your Office 365 tenant.
Export Office 365 users based on a specific license plan

Once run the above command, copy the the AccountSkuId value for the license that you want to filter.

Now copy the below script and replace AccountSkuId of license that you copied from the above step and run the modified script to list users who are assigned to a specific license in Office 365.
Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -eq "tenant:EMSPREMIUM"}

Export list of users who has a specific license to CSV file.

Run the below command to export office 365 users based on required or selected license plan.
Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -eq "tenant:EMSPREMIUM"} |
Select-Object UserPrincipalName, DisplayName |
Export-Csv "C:\O365Users.csv"  -NoTypeInformation -Encoding UTF8


No comments:

Post a Comment