Entra / Microsoft 365 · Licensing
Remove kaizala service plans
Disable Kaizala service plans from Microsoft 365 E1, E3, and E5 licenses.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
# Review required modules and connection steps before running.# Connect to Microsoft Graph or Exchange Online as needed for this script.
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
$KaizalaPlan3 = "aebd3021-9f8f-4bf8-bbe3-0ed2f4f047a1" #E3$KaizalaPlan2 = "54fc630f-5a40-48ee-8965-af0503c1386e" # E1$KaizalaStandalone = "0898bdbb-73b0-471a-81e5-20f1fe4dd66e" # E5$Office365E5NoConf = "26d45bd9-adf1-46cd-a9e1-51e9a5524128"$Office365E3 = "6fd2c87f-b296-42f0-b197-1e91e994b900"$Office365E5 = "c7df2760-2c81-4ef7-b578-5b5392b571df"$Office365E1 = "18181a46-0d4e-45cd-891e-60aabd171b4e"# Find and process licensed Azure AD users$LicenseUsers = [System.Collections.Generic.List[Object]]::new() ; $i =0Write-Host "Searching for licensed accounts"[array]$Users = Get-MgUser -PageSize 250 -Filter "assignedLicenses/`$count ne 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable Records -All | Sort-Object DisplayNameIf (!($Users)) {Write-Host "Oddly, we can't find any licensed users... exiting!" ; break}ForEach ($User in $Users) {$i++Write-Host ("Checking licenses assigned to account {0} {1}/{2}" -f $User.Displayname, $i, $Users.count)$License = $Null; $LicenseSkuId = $Null# Find out what SKU the account hasIf ($Office365E3 -in $User.AssignedLicenses.SkuId) { $LicenseSkuId = $Office365E3 }If ($Office365E5NoConf -in $User.AssignedLicenses.SkuId) { $LicenseSkuId = $Office365E5NoConf }If ($Office365E5 -in $User.AssignedLicenses.SkuId) { $LicenseSkuId = $Office365E5 }If ($Office365E1 -in $User.AssignedLicenses.SkuId) { $LicenseSkuId = $Office365E1 }# Examine service plans assigned to the account to see if they include Kaizala[array]$AllLicenses = Get-MgUserLicenseDetail -UserId $User.Id | Select-Object -ExpandProperty ServicePlans | Sort-Object ServicePlanId -Unique[array]$Licenses = $AllLicenses | Where-Object {$_.ProvisioningStatus -eq 'Success'}[array]$DisabledLicenses = $AllLicenses | Where-Object {$_.ProvisioningStatus -eq 'Disabled'}# Set the appropriate value for the Kaizala service plan appropriate for the licenseIf ($KaizalaPlan2 -in $Licenses.ServicePlanId) {$License = "Office 365 E1"; $ServicePlanId = $KaizalaPlan2}If ($KaizalaPlan3 -in $Licenses.ServicePlanId) {$License = "Office 365 E3"; $ServicePlanId = $KaizalaPlan3}If ($KaizalaStandalone -in $Licenses.ServicePlanId) {$License = "Office 365 E5"; $ServicePlanId = $KaizalaStandalone}If ($License) { # Update the assigned license on the account# Add any previously disabled license if they exist to the Kaizala service plan and compose the license options[array]$DisabledSPs = $DisabledLicenses.ServicePlanId$DisabledSPs += $ServicePlanId$LicenseOptions = @{SkuId = $LicenseSkuId ; DisabledPlans = $DisabledSPs}Write-Host ("Removing the Kaizala service plan from the {0} license for account {1}" -f $License, $User.DisplayName) -foregroundcolor RedTry {Set-MgUserLicense -UserId $User.Id -AddLicenses $LicenseOptions -RemoveLicenses @() | Out-Null$ReportLine = [PSCustomObject] @{User = $User.DisplayNameUPN = $User.UserPrincipalNameDepartment = $User.DepartmentCountry = $User.CountryLicense = $License}$LicenseUsers.Add($ReportLine)} Catch {Write-Host ("Failed to remove the Kaizala service plan from the {0} license for account {1}" -f $License, $User.DisplayName) -foregroundcolor Red}}}Clear-HostWrite-Host ("{0} Kaizala licenses were found and removed from these accounts:" -f $LicenseUsers.count)$LicenseUsers.User
Attribution
Author
Office365itpros