Microsoft Office 365 is a subscription-based service, and in large organizations, managing user licenses can be a challenge. PowerShell is a powerful tool that can simplify the process of checking and managing user licenses in Office 365. In this article, we will discuss how to check Office 365 user licenses using PowerShell in Windows.
We will go through some useful PowerShell commands that can help you gain insights into your users’ license statuses and other details.
Page Contents
Prerequisites
Before we get started, ensure that you have the following prerequisites in place:
- Administrator access: You must be a Global Administrator in your Office 365 tenant or have the necessary permissions to manage licenses.
- PowerShell: PowerShell should be installed on your Windows machine. PowerShell is included by default on most Windows systems, but if you don’t have it, you can download and install it from the Microsoft PowerShell website.
- MSOnline PowerShell module: Install the MSOnline PowerShell module by running the following command in an elevated PowerShell window:
Install-Module MSOnline
This module is required for connecting to your Office 365 tenant and managing licenses using PowerShell. Make sure you’re running PowerShell as an administrator when you execute theInstall-Module
command.
Also see: Run CMD, PowerShell or Regedit as SYSTEM in Windows 11
Connecting to Office 365 using PowerShell
To begin, open a PowerShell window as an administrator. You can do this by searching for “PowerShell” in the Windows Start menu, right-clicking on “Windows PowerShell,” and selecting “Run as administrator.”
Now, connect to your Office 365 tenant by running the following command:
Connect-MsolService
This command will prompt a login form to appear, allowing you to enter your Office 365 admin username and password. After entering your credentials, the connection to your Office 365 tenant will be established.
If you receive an error message stating that “Connect-MsolService is not recognized as the name of a cmdlet, function, script file, or operable program,” it indicates that you do not have the MSOnline module installed. Please refer to the previous section for instructions on installing the module before proceeding.
With the connection established, you can now proceed to retrieve user license information and manage licenses in your organization.
Related issue: Work or school account problem keeps popping up Windows 11
Retrieve available licenses
Get all license SKUs
Understanding the types of licenses available in your Office 365 tenant is essential for managing user licenses. The Get-MsolAccountSku command retrieves all the available licenses in your tenant, providing details such as the total number of licenses, the number of consumed licenses, and the remaining licenses available for assignment.
Get-MsolAccountSku
This command can help you identify if you need to purchase additional licenses or if you have unused licenses that can be assigned to new users.
Display SKU part numbers
If you only need a simplified list of the available licenses, displaying just the SKU part numbers can be helpful. The SKU part number is a unique identifier for each license type.
(Get-MsolAccountSku).SkuPartNumber
By using this command, you can quickly determine which licenses you have available in your tenant, making it easier to identify specific licenses when assigning them to users.
Retrieve user information
Get all users
An essential step in managing user licenses is obtaining a list of all users in your Office 365 tenant. The Get-MsolUser command with the -All switch retrieves this information.
Get-MsolUser –All
This command provides you with a comprehensive list of all user accounts, including their properties such as display names, user principal names, and license statuses.
Retrieve specific user properties
In some cases, you might want to retrieve only specific properties for each user, such as Display Name, Department, IsLicensed, and Usage Location. The Get-MsolUser command with the Select keyword allows you to choose the properties you want to display.
Get-MsolUser -All | Select DisplayName, Department, IsLicensed, UsageLocation
Filter users based on license status
To manage user licenses effectively, you may need to filter users based on their license status. This can help you identify users who need licenses or those who have unnecessary licenses assigned.
Get only licensed users
To filter and display only the licensed users, use the Get-MsolUser command with the Where-Object keyword and the $_.IsLicensed -eq $true condition.
Get-MsolUser -All | Where-Object {$_.IsLicensed -eq $true}
This command helps you identify users who have an assigned license, which can be useful for tracking license usage and ensuring compliance.
List unlicensed users
If you want to list all unlicensed users, use the Get-MsolUser command with the -UnlicensedUsersOnly switch and the -All switch.
Get-MsolUser –UnlicensedUsersOnly -All
By identifying unlicensed users, you can ensure that all necessary users have the appropriate licenses and access to Office 365 services.
Filter users based on license type
Sometimes, it’s crucial to filter users with a specific license type, such as “EnterprisePremium”. This can help you verify that users have the correct licenses assigned or to track the usage of a particular license type.
To filter users with a specific license type, use the Get-MsolUser command with the Where-Object keyword and the ($_.licenses).AccountSkuId -match “EnterprisePremium” condition.
Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "EnterprisePremium"}
Export user information to a file
Export all users to a CSV file
To export a list of all users to a CSV file, use the Get-MsolUser command with the -All switch and the Out-File cmdlet. This command is particularly useful when you need to share user information with your team or analyze the data using spreadsheet software like Microsoft Excel.
Get-MsolUser -All | Out-file C:\allusers.csv
By exporting user information to a CSV file, you can easily manipulate and analyze the data, create reports, or import the data into other systems for further processing.
Retrieve users from a specific department
List users by department
To filter and display users belonging to a specific department, use the Get-MsolUser command with the Where-Object keyword and the $_.Department -eq “DepartmentName” condition. Replace “DepartmentName” with the name of the department you want to filter.
Get-MsolUser -All | Where-Object {$_.Department -eq "DepartmentName"}
This command can help you manage user licenses within specific departments, ensuring that all users within a department have the appropriate licenses assigned.
Conclusion
PowerShell is a valuable tool for managing Office 365 user licenses in Windows. By understanding and using the commands discussed in this article, you can efficiently check, filter, and export user license information. With this knowledge, you’ll be able to better manage your organization’s Office 365 environment and make informed decisions regarding license assignments and usage.