🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

Assigning Multiple Licenses Using Graph PowerShell

Manually assigning multiple licenses to each user in Microsoft 365 can be a time-consuming task, especially in larger organizations. This article addresses that challenge by demonstrating how to assign multiple licenses to both individual users and multiple users using Graph PowerShell automation. The scripts below allow administrators to streamline this process efficiently.


Assigning Multiple Licenses to a Single User

Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All
# Get the SKUs for the licenses you want to assign
$EmsSku = Get-MgSubscribedSku -All | Where-Object { $_.SkuPartNumber -eq 'EMSPREMIUM' }
$FlowSku = Get-MgSubscribedSku -All | Where-Object { $_.SkuPartNumber -eq 'FLOW_FREE' }
                                
# Create an array of licenses to assign
$addLicenses = @(
    @{SkuId = $EmsSku.SkuId},
    @{SkuId = $FlowSku.SkuId}
)
                                
# Assign the licenses to the user
Set-MgUserLicense -UserId 'user-id-here' -AddLicenses $addLicenses -RemoveLicenses @()
                            

How the Script Works

  • First, the script connects to Microsoft Graph using the required scopes.
  • It retrieves the license SKUs (EMSPREMIUM and FLOW_FREE) via Get-MgSubscribedSku.
  • An array is built containing the SKUs you want to assign.
  • Finally, Set-MgUserLicense assigns those licenses to the specified user (replace 'user-id-here' with the actual user ID or UPN).

Note: To find available license SkuPartNumber values, run:

Get-MgSubscribedSku | Select-Object SkuId, SkuPartNumber


Assigning Multiple Licenses to Multiple Users

# Get the SKUs for the licenses you want to assign
$PPSku = Get-MgSubscribedSku -All | Where-Object { $_.SkuPartNumber -eq 'Power_Pages_vTrial_for_Makers' }
$FlowSku = Get-MgSubscribedSku -All | Where-Object { $_.SkuPartNumber -eq 'FLOW_FREE' }
                                
# Create an array of licenses to assign
$addLicenses = @(
    @{SkuId = $PPSku.SkuId},
    @{SkuId = $FlowSku.SkuId}
)
                                
$csvUsers = Import-Csv "C:\users\testuser\downloads\users.csv"
foreach ($user in $csvUsers) {
    Set-MgUserLicense -UserId $user.UserId -AddLicenses $addLicenses -RemoveLicenses @()
}
                            

How This Script Works

  • This script fetches the necessary license SKUs.
  • It builds the license assignment array just like in the previous example.
  • The list of users is read from a CSV file containing a UserId column.
  • Each user in the list is assigned the licenses using a foreach loop.

Make sure your CSV has a header column named UserId, containing either the user UPN or object ID.

Further Enhancements

  • CSV Validation: Add checks to ensure valid user IDs exist before processing.
  • Logging: Implement output logging to a CSV or text file for auditing purposes.
  • Error Segregation: Record failed and successful license assignments in separate files.
  • Remove Licenses: Extend functionality to remove specific licenses dynamically.

Possible Errors & Solutions

Error Cause Solution
Set-MgUserLicense : Request_BadRequest Invalid or missing SKU ID Verify SKU ID using Get-MgSubscribedSku
User not found Incorrect UPN or user ID in CSV file Double-check and validate input file
Insufficient privileges to complete the operation Missing delegated/admin permissions Ensure the user has appropriate Graph API permissions
FlowSku or other SKU returns $null SKU is not available in your tenant Use Get-MgSubscribedSku to confirm SKU availability

Conclusion

Using Microsoft Graph PowerShell, administrators can efficiently assign multiple licenses to users in bulk or individually. This approach minimizes manual efforts and ensures consistent license provisioning across the organization. Whether you're onboarding new users or managing trial subscriptions, the scripts above provide a powerful, reusable framework for licensing automation.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

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