Manage direct assigned Licenses and Service Plans with Microsoft.Graph

Manage direct assigned Licenses and Service Plans with Microsoft.Graph

Hi All,

A few Weeks ago i did write a Blog Article how to Keep Track of new ServicePlans in M365 Licenses with Azure Automate and Microsoft.Graph PowerShell Modules.

I received a Question, how to add or remove specific Service Plans to a License for a specific User.

Basically there are two methods:

I wrote a Blog Article on how to add and remove Licenses with Microsoft.Graph

#Remove License
Set-MgUserLicense -UserId -AddLicenses @() -RemoveLicenses @('e43b5b99-8dfb-405f-9987-dc307f34bcbd') #PhoneSystem

#Add License
Set-MgUserLicense -UserId -AddLicenses @{SkuId = 'e43b5b99-8dfb-405f-9987-dc307f34bcbd'} -RemoveLicenses @() #PhoneSystem

In this Article, i will explain how to remove a specific Service Plan for a SKU (License) for a User.

First of all, we need to see what Licenses are assigned to a user

Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All -NoWelcome
Get-MgUserLicenseDetail -UserId

List Service Plans for a SKU (SPE_E3 in this case here)

$Licenses = Get-MgUserLicenseDetail -UserId
$Licenses | where {$_.SkuPartNumber -eq "SPE_E3"} | select -ExpandProperty ServicePlans

You can verify the SKU and ServicePlan ID’s here and even download a CSV File.

I’ve written a short PowerShell Script to download the CSV File and use it in PowerShell

$Result = Invoke-Webrequest -Uri
$CSVString = [System.Text.Encoding]::UTF8.GetString($Result.Content)
Set-Content -Path "$env:TEMP\licensing.csv" -Value $CSVString
$CSV = Import-CSV -Path "$env:TEMP\licensing.csv"

List a Service Plan from a Specific License

$CSV | where {$_.String_id -eq "SPE_E3" -And $_.Service_Plan_Id -eq "a82fbf69-b4d7-49f4-83a6-915b2cf354f4"}

Let’s see what SKU’s are assigned to my user and list the DisabledPlans

$User = Get-MgBetaUser -UserId
$User.AssignedLicenses | ft skuid, DisabledPlans
$User.AssignedLicenses[0] | select -ExpandProperty DisabledPlans

Now we create a new Object and add the VIVAENGAGE_CORE ServicePlan Id to the DisabledPlans and assign the Object as new Licensing Object to the User.

$DisabledPlans = ($user.AssignedLicenses | where {$_.SkuID -eq "05e9a617-0261-4cee-bb44-138d3ef5d965"}).DisabledPlans #SPE_E3
$DisabledPlans += "a82fbf69-b4d7-49f4-83a6-915b2cf354f4" #VIVAENGAGE_CORE

$LicenseAndServicePlan = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense
$LicenseAndServicePlan.SkuId = "05e9a617-0261-4cee-bb44-138d3ef5d965" #SPE_E3
$LicenseAndServicePlan.DisabledPlans = $DisabledPlans
$Status = Set-MgUserLicense -UserId -AddLicenses $LicenseAndServicePlan -RemoveLicenses @()

When i check the M365 Admin Center the Service Plan is now disabled

The ServicePlan for IVAENGAGE_CORE is now also disabled in PowerShell

$Licenses = Get-MgUserLicenseDetail -UserId
$Licenses | where {$_.SkuPartNumber -eq "SPE_E3"} | select -ExpandProperty ServicePlans

Summary: You have learned how to Manage direct assigned Licenses and Service Plans with Microsoft.Graph.

Andres Bohren

EntraID Logo

M365 Logo

PowerShell Logo