PowerShell Script to List Microsoft 365 Licenses for Multiple Users
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.

- 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.
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.
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.
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.
Open your PowerShell console as an administrator and execute 'Connect-MsolService'. Enter your Microsoft 365 admin credentials when prompted.
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.
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 Microsoft Graph PowerShell SDK
Utilize the modern Microsoft Graph module to retrieve user license details securely, ensuring long-term script functionality.
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. Download the Installer: Navigate to the official WPS Office website and download the free version for your operating system.
- 2. Install WPS Office: Run the downloaded executable file and follow the straightforward setup wizard to install the suite.
- 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, or PowerPoint files without losing any formatting.

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.




