How many times have you logged into Office 365 via PowerShell and had someone interrupt your work to request information about O365 licensing, only to discover that gathering this info via PowerShell is not the most pleasant experience?
Some of you may be thinking, “Well, I can just go to the portal and get the information by creating a filter for the license type, etc.” Great! But what if you don’t want to take the extra time it takes to login, navigate, etc.? As you may already know, the information is accessible via PowerShell; but did you know you can gather the information they need, right in PowerShell, without having to open a web browser?
The following commands need to execute while you have an active connection to Azure AD. If you need instructions on how to do this, Microsoft provides a guide here.
How to pull license information via PowerShell:
- View account license and service details with Office 365 PowerShell
- View user accounts with Office 365 PowerShell
The following are some simple one-liners to get at the information quickly. I converted them into functions for quick use, and to enable you to incorporate them into any existing function rich script, etc. But this is by no means essential.
Oh, and if you’re confused about the SKUs, here’s a site that helps you decipher them.
Commands
This example gathers all the available SKUs in your tenant:
Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | FT -AutoSize
Export the same information to CSV:
Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | Export-Csv FileName.csv -NoTypeInformation
This example gathers all licensed users with the corresponding license in use:
Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}}
Export the same information to CSV:
Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}} | Export-Csv FileName.csv -NoTypeInformation
This example gathers all the unlicensed users:
Get-MsolUser -All -UnlicensedUsersOnly | Select DisplayName, UserPrincipalName
Export the same information to CSV:
Get-MsolUser -All -UnlicensedUsersOnly | Select DisplayName, UserPrincipalName | Export-Csv FileName.csv -NoTypeInformation
While the previous commands accomplish their tasks, what if you want a function?
What is a PowerShell function, you ask?
PowerShell Functions
In PowerShell 6 About Functions, Microsoft describes a function as “a list of PowerShell statements that has a name that you assign. When you run a function, you type the function name. The statement in the list run as if you had typed them as the command prompt.”
I create functions for commands I run often. You may take this a step further and create a full module with all your functions. Writing your own PowerShell module is beyond the scope of this post, but it is possible. If you’re interested, check out Microsoft’s How to Write a PowerShell Script Module.
Get-TenantLicenses – The function below may be utilized to display the licenses available to the tenant:
Function Get-TenantLicenses { Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | FT -AutoSize }
Once the function has been executed, you can simply run Get-TenantLicenses to execute everything in the function.
Export-TenantLicense -Export filename.csv – The function below may be utilized to export the licenses available to the tenant in CSV format:
Function Export-TenantLicenses ($Export) { Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | Export-Csv $Export -NoTypeInformation }
Once the function is executed, you can simply run Export-TenantLicense -Export filename.csv to execute everything in the function and export a file with the name you specify.
Get-TenantUserLicenses – The function below may be utilized to display tenant users licensed with the corresponding license:
Function Get-TenantUserLicenses { Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}} }
Once the function is executed, you can simply run Get-TenantUserLicenses to execute everything in the function.
Export-TenantUserLicense -Export Filename.csv – The function below may be utilized to export the tenant users licensed with the corresponding license:
Function Export-TeanantUserLicenses ($Export) { Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}} | Export-Csv $Export -NoTypeInformation }
Once the function is executed, you can simply run Export-TenantUserLicense -Export Filename.csv to execute everything in the function and export a file with the name you specify.
Get-TenantUserNoLicenses – The function below may be utilized to display unlicensed tenant users:
Function Get-TenantUserNoLicenses { Get-MsolUser -All -UnlicensedUsersOnly | Select DisplayName, UserPrincipalName }
Once the function is executed, you can simply run Get-TenantUserNoLicenses to execute everything in the function.
Export-TenantNoUserLicense -Export Filename.csv – The function below may be utilized to export unlicensed tenant users:
Get-MsolUser -All -UnlicensedUsersOnly | Select DisplayName, UserPrincipalName | Export-Csv FileName.csv -NoTypeInformation
Once the function is executed, you can simply run Export-TenantNoUserLicense -Export Filename.csv to execute everything in the function and export a file with the name you specify.
Modifiying the above functions to suit your unique needs can save time and cut down on the distractions that go along with opening a browser. ???? If you enjoyed this post, Anexinet offers many additional Office 365-related posts, available here. Further, Anexinet offers a Cloud Strategy Kickstart to help accelerate your journey to Azure, or other platforms. Lastly, if you have a question about anything Cloud, Azure or Office 365-related, please don’t hesitate to contact us. We’d love to help you get started.

Jaime Perez
Cloud Consultant
With two decades in the industry, Jaime Perez is a consultant on our Hybrid IT & Cloud Services Team, focused on Office 365, Azure Site Recovery and Azure projects. An avid Exchange, Teams, Power BI and Data Science enthusiast, Jaime also leads the Philadelphia Cloud Technologies User Group. JP is an Office 365 Solutions Associate as well as a Microsoft-certified solutions expert in productivity/messaging, Cloud Platform, infrastructure, and data science.
Let’s get the conversation started
Reach out now to begin your digital transformation
+ 16,659
ZOOM MEETINGS
+ 9,789
HAPPY CLIENTS
+ 5,075
FINISHED PROJECTS
+ 133,967,432
LINES OF CODE
© 2000 - 2021 Anexinet Corp., All rights reserved | Privacy Policy | Cookie Policy
This website uses cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL cookies.
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.