logo
search
License & Subscription Issues

PowerShell Script to List Microsoft 365 Licenses for Multiple Users

Huma Ashraf ChHuma Ashraf Ch Sep 30, 2026 869 views

Question details

The user needs to retrieve Microsoft 365 licenses, service plans, and provisioning statuses for a batch of users by importing a CSV file through a PowerShell script.

How to List Microsoft 365 Licenses for Multiple Users using PowerShell
Product
Microsoft 365
Device & OS
not provided
Scenario
An IT administrator needs to audit or verify the assigned licenses and service statuses of multiple Microsoft 365 users listed in a CSV file.
Observed behavior
The goal is to successfully iterate through the users and display their exact Microsoft 365 license SKUs and service plan statuses on the console or export them.
Before you start

Ensure you have the MSOnline or Microsoft Graph PowerShell module installed, and verify that your account has Global Administrator or User Management Administrator permissions in your Microsoft 365 tenant.

Solution 1Recommended

Use the MSOnline Module (Connect-MsolService)

Import the user principal names from a CSV file and iterate through the MsolUser license collections to display assigned SKUs and service statuses.

This method relies on the MSOnline module. The script imports a CSV file, loops through each user using Get-MsolUser, and iterates through both the Licenses and ServiceStatus properties to extract the required data.

1
Prepare your CSV file

Create a CSV file named 'users.csv' and ensure it has a column header named 'UserPrincipalName' containing the email addresses of the users you want to query.

2
Connect to Microsoft Online

Open your PowerShell console as an administrator and execute 'Connect-MsolService'. Enter your Microsoft 365 admin credentials when prompted.

3
Import users and retrieve licenses

Run a foreach loop over 'Import-Csv -Path C:\path\to\users.csv'. Inside the loop, use 'Get-MsolUser -UserPrincipalName $_.UserPrincipalName' to fetch the user object.

4
Iterate through the collections

Within the loop, iterate through '$User.Licenses' and then through '$License.ServiceStatus'. Output the 'AccountSkuId' (license SKU), 'ServicePlan.ServiceName' (service-plan name), and 'ProvisioningStatus' (status) to your console or export them.

Use the MSOnline Module (Connect-MsolService)
Deprecation Notice: Microsoft is in the process of deprecating the MSOnline module. It is highly recommended to plan a transition to the Microsoft Graph PowerShell SDK for future administrative scripts.
Free Microsoft Office alternative

Simplify Your Document Management with WPS Office

Managing expensive Microsoft 365 subscriptions and licenses can be a heavy burden for growing teams. If you need a powerful, cost-effective alternative for daily document editing without the complexity of cloud licensing, WPS Office offers a complete suite tailored to your needs.

  1. 1. Download the Installer: Navigate to the official WPS Office website and download the free version for your operating system.
  2. 2. Install WPS Office: Run the downloaded executable file and follow the straightforward setup wizard to install the suite.
  3. 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, or PowerPoint files without losing any formatting.
No complex cloud licensing scripts required—simply install and use right away.Fully compatible with Microsoft Office formats, including .docx, .xlsx, and .pptx.Lightweight architecture ensures fast performance on older or budget hardware.All-in-one interface combining Writer, Presentation, Spreadsheet, and PDF tools.Free to use for standard document creation, lowering overhead costs.
microsoft office alternative - wps office

Frequently Asked Questions

What permissions do I need to run the MSOnline PowerShell script?

You need elevated Microsoft 365 administrative privileges. Specifically, your account must be assigned the Global Administrator or User Management Administrator role to query user licenses using the Get-MsolUser cmdlet.

Why is my CSV file not importing correctly in PowerShell?

Ensure your CSV file is properly formatted with a clear header row. For this script, the header must exactly match the property name you are referencing in your script loop, such as 'UserPrincipalName', with no extra spaces.

Can I export the retrieved license details to a new CSV file instead of displaying them?

Yes. You can capture the output of your loops into a custom PSCustomObject array, and then pipe those results to the 'Export-Csv -Path C:\output.csv -NoTypeInformation' command to save the data.

What is the difference between MSOnline and Microsoft Graph PowerShell?

MSOnline is an older PowerShell module used for Azure AD and Microsoft 365 management that is currently being phased out. Microsoft Graph is the modern, recommended API and PowerShell SDK that provides enhanced security and will receive future updates.