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.
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.
Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | FT -AutoSize
Get-MsolAccountSku | Select AccountSkuID, SkuPartNumber, ActiveUnits, WarningUnits, ConsumedUnits | Export-Csv FileName.csv -NoTypeInformation
Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}}
Get-MsolUser -All | where {$_.isLicensed -eq $true} | Select-Object DisplayName, UserPrincipalName, @{name="Licenses";expression={$_.licenses.accountskuid}} | Export-Csv FileName.csv -NoTypeInformation
Get-MsolUser -All -UnlicensedUsersOnly | Select DisplayName, UserPrincipalName
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?
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.
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.
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.
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.
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.
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.
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.
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.