Microsoft Office 365 licenses include many products and services – Exchange, SharePoint, Teams, etc. However, when organizations first adopt Office 365, many administrators deactivate some of these individual services. In this post, you will learn how to determine which Office 365 license services are disabled for a user and how to enable one or all of them using PowerShell.

For this tutorial, you will need:

  • Administrator access to your Office 365 tenant, such as Global Administrator or User Administrator
  • PowerShell version 7 (although 5.1 is also acceptable)

Connect to Microsoft Graph PowerShell

First, you need the Microsoft Graph PowerShell module to manage user licenses. To install this module:

  1. Open a PowerShell console.
  2. Run the following command to install the Graph module:

    Install-Module -Name Microsoft.Graph

    If you receive a warning about installing from an untrusted repository, enter Y and press Enter to continue the installation. If you receive a notification about requiring administrator rights to install the module, use the following command to install the module at the current user scope:

    Install-Module -Name Microsoft.Graph
  1. Use the following command to connect to your tenant. The Scope parameter specifies the necessary graph permissions to perform user license administration.

    Connect-MgGraph -Scope Directory.AccessAsUser.All, Directory.ReadWrite.All

To learn more about getting started with the Microsoft Graph PowerShell module, check out Microsoft Graph PowerShell Module: Getting Started Guide!

View Office 365 Licenses

To view available Office 365 licenses in your tenant, use the Get-MgSubscribedSku command. Use Select-Object to focus on the SkuId and SkuPartNumber properties. You will need the SkuId later, and the SkuPartNumber describes the license type.

Get-MgSubscribedSku | Select-Object SkuId, SkuPartNumber
Get-MgSubscribedSku office 365 license powershell
View available tenant licenses

The SkuPartNumber property describes what type of license it is. For example, ENTERPRISEPACK is the E3 license. For a complete list of product names and their string identifiers, check out this Microsoft Docs article.

Licenses consist of service plans, which are additional products or features included in the license. For example, the E3 or ENTERPRISEPACK license includes service plans for Exchange Online, SharePoint, Microsoft Teams, OneDrive, and others.

To view the service plans included in a license, use the Get-MgSubscribedSku command again with the All parameter. Use Where-Object to filter out the licenses based on SkuPartNumber, then select and expand the ServicePlans property. You will see the additional service plans included in the license and their current provisioning status.

Get-MgSubscribedSku |
    Where-Object -Property SkuPartNumber -eq -Value 'ENTERPRISEPACK' |
    Select-Object -ExpandProperty ServicePlans
get-mgsubscribedsku view license service plans
Viewing service plans included in a license

View User’s Assigned Licenses

Use the Get-MgUser command to view licenses currently assigned to a user account by viewing the AssignedLicenses property. When using the Get-MgUser command, use the Property parameter to specify returning the AssignedLicenses property as it is not in the default data return.

The following examples demonstrate various ways to retrieve the user’s assigned licenses. The first example returns the licenses, while the second example saves the results to a variable and then accesses them using dot notation.

# First example
Get-MgUser -UserId <UserId> -Property AssignedLicenses |
    Select-Object -ExpandProperty AssignedLicenses
# Second example
$user = Get-MgUser -UserId <UserId> -Property AssignedLicenses
$user.AssignedLicenses
Get-MgUser microsoft graph powershell
View licenses assigned to a user account

In the screenshot above, only the SkuId is displayed, which is why it is helpful to view all the SKUs available in the tenant. You will need to match the SkuId assigned to the user from the subscribed SKUs in the tenant.

Assign Office 365 License using PowerShell

Use the Set-MgUserLicense command to assign a license to a user. Specify the licenses to add using the AddLicenses parameter with a hashtable consisting of the SkuId and value. You must also include the RemoveLicenses parameter with an empty array even if you are not removing licenses.

The example below adds the license Microsoft Power Automate Free license to the user account. This license has a SkuPartNumber of “FLOW_FREE” and a SkuId of “f30db892-07e9-47e9-837c-80727f46fd3d”.

Set-MgUserLicense `
    -UserId jeff@jeffbrown.tech `
    -AddLicenses @{ SkuId = 'f30db892-07e9-47e9-837c-80727f46fd3d'} `
    -RemoveLicenses @()

Assign a License with Disabled Service Plans

Recall from earlier that a license includes service plans that provide access to different services or capabilities. You can also assign a license while turning off service plans.

First, use the Get-MgSubscribedSku command again and filter out which license you want to assign. This example assigns the E3 or ENTERPRISEPACK license.

$e3 = Get-MgSubscribedSku |
    Where-Object -Property SkuPartNumber -eq -Value 'ENTERPRISEPACK'

Next, create a variable named $disabledPlans that filters off $e3.ServicePlans where ServicePlanName equals the services you wish to disable. The disabled plans in this example include Microsoft Bookings (MICROSOFTBOOKINGS) and Yammer (YAMMER_ENTERPRISE).

Hint: To find service plan names, go back to the View Available License section where you filtered and expanded the service plan information for a license.

$disabledPlans = $e3.ServicePlans |
    Where-Object ServicePlanName -in ("MICROSOFTBOOKINGS", "YAMMER_ENTERPRISE") |
    Select-Object -ExpandProperty ServicePlanId

Next, build a new license object variable that is an array with a single hashtable. The hashtable includes SkuId of the license you want to assign. You will also have a DisabledPlans key with a value of the $disabledPlans variable.

Finally, use the Set-MgUserLicense command again and assign the $addLicenses variable to the AddLicenses parameter. Again, don’t forget to include the RemoveLicenses parameter with an empty array.

$addLicenses = @(
    @{
        SkuId         = $e3.SkuId
        DisabledPlans = $disabledPlans
    }
)
Set-MgUserLicense `
    -UserId jeff@jeffbrown.tech `
    -AddLicenses $addLicenses `
    -RemoveLicenses @()

Office 365 License and PowerShell Summary

In this tutorial, you learned how to install and connect to your tenant using the Microsoft Graph PowerShell module. You viewed the Office 365 license and service plans for a user account, and you enabled one or all service plans for a user, all using PowerShell!

Have you enjoyed this article? Check out more PowerShell articles here!