Assign Microsoft 365 License Using Graph PowerShell

Follow these steps to assign Microsoft 365 User License to users using the Microsoft Graph PowerShell module.

Install the Microsoft Graph PowerShell SDK

If you haven't already, install the Graph PowerShell module by running: Install-Module Microsoft.Graph -Scope CurrentUser

Connect to Microsoft Graph and Authenticate Yourself

Before you can interact with Microsoft Graph, you need to authenticate yourself with the required permissions. The required permissions in our case is User.Read.All and Directory.ReadWrite.All

Running the Connect-MgGraph -Scopes "User.Read.All", "Directory.ReadWrite.All" command will open a login prompt for you to enter your Microsoft 365 credentials and authenticate yourself.

Using Get-MgSubscribedSku cmdlet to get Microsoft 365 License ID

Run Get-MgSubscribedSku -All command to get all the license IDs you might have in your tenant. Your license ID comes after AccountID as shown in the image.


Using Get-MgUser to get the UserPrincipalName or User ID

Run Get-MgUser command and find out the UserPrincipalName or the user ID of the user who is going to be assigned the Microsoft 365 License.



Using Set-MgUserLicense cmdlet to assign Microsoft 365 License

Run Set-MgUserLicense cmdlet and pass the user id to the -UserId parameter and the license ID to the -AddLicenses parameter as shown in the image.

Note: If there are any assigned licenses you wish to remove, details of it can be passed to -RemoveLicenses @() parameter. -RemoveLicenses parameter is required - even if it is empty - for the Set-MgUserLicense cmdlet to execute successfully.


Using Get-MgUserLicenseDetail cmdlet to verify license assignment

To ensure the license was successfully assigned, you can retrieve the user's license information by executing the Get-MgUserLicenseDetail cmdlet and passing in the UserId to the -UserId parameter .



Assign Microsoft 365 License to Multiple Users

1. Add the UserPrincipalNames of all unlicensed users in an array (as shown in the image) and store them in a variable.


2. Next run Get-MgSubscribedSku cmdlet to get the license ID to be assigned to the users and store it in a variable.


3. Execute this PowerShell script - that includes the users variable and the license ID variable - to assign licenses to the users.

The PowerShell script loops through the list of unlicensed users and executes Set-MgUserLicense cmdlet for each one of them to assign the license.

Note: Read Microsoft Documentation on Assigning Microsoft 365 License using Graph PowerShell for more information.


Suggested Reading

© m365corner.com. All Rights Reserved. Design by HTML Codex