Bulk license assign

Lycee Francais 0 Reputation points
2024-10-07T20:30:41.5166667+00:00

need to bulk assign license with powershell for all unlicensed users

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,924 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wesley Li 11,140 Reputation points
    2024-10-08T16:16:14.1966667+00:00

    Hello,

    To bulk assign licenses to all unlicensed users using PowerShell, you can follow these steps:

    1.Connect to Microsoft 365: First, you need to connect to Microsoft 365 with PowerShell. You can use the Microsoft Graph PowerShell SDK for this purpose. Run the following command to connect:

    Connect-Graph -Scopes User.Read.All

    2.Get Unlicensed Users: Next, you need to get a list of all unlicensed users. You can use the following command to retrieve this list:

    $unlicensedUsers = Get-MsolUser -All | Where-Object { $_.isLicensed -eq $false }

    3.Assign Licenses: Finally, you can assign licenses to these unlicensed users. Replace <AccountSkuId> with your actual AccountSkuId. Use the following command to assign the licenses:

    foreach ($user in $unlicensedUsers) {

        Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses "<AccountSkuId>"

    }

    This script will loop through all unlicensed users and assign the specified license to each of them.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.