Managing Microsoft 365 licenses using PowerShell

Managing Microsoft 365 licenses using PowerShell

Managing licenses for Microsoft 365 can be a daunting task, especially when you have a large number of users. However, PowerShell provides a powerful and efficient way to manage licenses in Microsoft 365. In this article, we will walk you through the steps to manage Microsoft 365 licenses using PowerShell.


Steps to manage Microsoft 365 licenses using PowerShell.


1. Connect to Microsoft 365 PowerShell: 


To get started, launch PowerShell as an administrator and connect to Microsoft 365 PowerShell. You can do this by running the following command:


  1. Connect-MsolService


This command will prompt you to enter your Microsoft 365 admin credentials. Once you have entered your credentials, you will be connected to Microsoft 365 PowerShell.


2. Get a list of all available licenses: 


Once you are connected to Microsoft 365 PowerShell, you can get a list of all available licenses by running the following command:


  1. Get-MsolAccountSku


This command will return a list of all available licenses in Microsoft 365, along with their unique SKU IDs.


3. Get a list of all users with assigned licenses: 


To view a list of all users in your organization who have been assigned licenses, run the following command:


  1. Get-MsolUser -All | Where-Object {$_.isLicensed -eq "True"}


This command will return a list of all users who have been assigned licenses, along with the details of the licenses they have been assigned.


4. Assign licenses to users: 


To assign a license to a user, you can use the Set-MsolUserLicense cmdlet. Run the following command to assign a license to a single user:


  1. Set-MsolUserLicense -UserPrincipalName user@domain.com -AddLicenses "ENTERPRISEPACK"


Replace "user@domain.com" with the email address of the user you want to assign the license to. Replace "ENTERPRISEPACK" with the SKU ID of the license you want to assign.


You can also assign licenses to multiple users at once using PowerShell. To assign licenses to multiple users, create a CSV file with the following columns: 

UserPrincipalName, AccountSkuId, and UsageLocation. For each user, enter their email address, the SKU ID of the license you want to assign, and the usage location (e.g. US, UK, etc.). Then, run the following command:


  1. Import-Csv "C:\Users.csv" | ForEach-Object {Set-MsolUserLicense -UserPrincipalName $.UserPrincipalName -AddLicenses $.AccountSkuId -UsageLocation $_.UsageLocation}


Replace "C:\Users.csv" with the path to the CSV file you created.


5. Remove licenses from users: 


To remove a license from a user, use the Set-MsolUserLicense cmdlet again. Run the following command to remove a license from a single user:


  1. Set-MsolUserLicense -UserPrincipalName user@domain.com -RemoveLicenses "ENTERPRISEPACK"


Replace "user@domain.com" with the email address of the user you want to remove the license from. Replace "ENTERPRISEPACK" with the SKU ID of the license you want to remove.


You can also remove licenses from multiple users at once using PowerShell. To remove licenses from multiple users, create a CSV file with the following columns: UserPrincipalName, AccountSkuId, and UsageLocation. For each user, enter their email address, the SKU ID of the license you want to remove, and the usage location (e.g. US, UK, etc.). Then, run the following command:


  1. Import-Csv "C:\Users.csv" | ForEach-Object {Set-MsolUserLicense -UserPrincipalName $.UserPrincipalName -RemoveLicenses $.AccountS


6. View license details for a specific user: 


To view the details of the licenses assigned to a specific user, run the following command:


  1. Get-MsolUser -UserPrincipalName user@domain.com | Select-Object DisplayName, Licenses


Replace "user@domain.com" with the email address of the user you want to view license details for.


7. View license details for all users: 


To view the details of the licenses assigned to all users in your organization, run the following command:


  1. Get-MsolUser -All | Select-Object DisplayName, UserPrincipalName, @{N="Licenses";E={$_.Licenses.AccountSkuId}}


This command will return a list of all users in your organization along with the details of the licenses they have been assigned.


8. Disable a specific license for all users: 


To disable a specific license for all users in your organization, run the following command:


  1. Get-MsolAccountSku | Where-Object {$.SkuPartNumber -eq "ENTERPRISEPACK"} | ForEach-Object {Set-MsolUserLicense -AccountSkuId $.AccountSkuId -UserPrincipalName $_.AccountSkuId -DisabledPlans "SHAREPOINTWAC_EDU"}


Replace "ENTERPRISEPACK" with the SKU ID of the license you want to disable. Replace "SHAREPOINTWAC_EDU" with the SKU ID of the specific plan you want to disable.



Conclusion:


In conclusion, PowerShell provides a powerful and efficient way to manage Microsoft 365 licenses. With PowerShell, you can quickly and easily assign licenses to users, remove licenses from users, view license details for specific users or all users, and disable specific licenses for all users. By using PowerShell to manage licenses, you can save time and ensure that your organization is properly licensed and compliant.


    • Related Articles

    • Configuring and Managing Microsoft 365 Exchange Online: A Technical overview

      Microsoft 365 Exchange Online is a cloud-based email messaging service designed to meet the communication needs of businesses of all sizes. Configuring and managing Exchange Online can be a complex task, but with the right knowledge and tools, it can ...
    • Deep Dive into Microsoft 365 PowerShell Scripting

      Microsoft 365 lets administrators manage user accounts, licenses, settings, and more online via a web-based administrative console. Although the console provides a user-friendly interface for managing Microsoft 365, it can be complex when it comes to ...
    • Managing Microsoft 365 SharePoint sites and content with PowerShell

      Managing Microsoft 365 SharePoint sites and content can be a challenging task, especially when dealing with large amounts of data. To simplify this process, administrators can take advantage of PowerShell scripting to automate various management ...
    • How to automate user management in Microsoft 365 with PowerShell

      Introduction: Managing users in Microsoft 365 can be a time-consuming task, especially for larger organizations. With PowerShell, however, you can automate many of the tasks involved in user management, making the process faster and more efficient. ...
    • Microsoft 365 Exchange Online - Shared Mailboxes & PowerShell

      Introduction Overview of Shared Mailboxes A shared mailbox in Microsoft 365 Exchange Online allows multiple users to access and manage emails, contacts, and calendar events from a single mailbox. It is commonly used by teams that need to collaborate ...