I was able to modify one of the example scripts on the page as shown:
$userLicense = Get-MgUserLicenseDetail -UserId "TESTUSER@TEST.COM"
$userDisabledPlans = $userLicense.ServicePlans | `
Where ProvisioningStatus -eq "Disabled" | `
Select -ExpandProperty ServicePlanId
$e3Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'ENTERPRISEPACK'
$newDisabledPlans = $e3Sku.ServicePlans | `
Where ServicePlanName -in ("SWAY") | `
Select -ExpandProperty ServicePlanId
$disabledPlans = ($userDisabledPlans + $newDisabledPlans) | Select -Unique
$addLicenses = @(
@{
SkuId = $e3Sku.SkuId
DisabledPlans = $disabledPlans
}
)
Set-MgUserLicense -UserId "TESTUSER@TEST.COM" -AddLicenses $addLicenses -RemoveLicenses @()
This script will disable the "SWAY" service plan for the specified E3 licensed user while leaving all other service plans untouched and works perfectly.
Now I want to try reversing it, rather than disabling the service "SWAY" service plan I want to enable it, while leaving all other service plans untouched. I tried to modify the script as follows:
$userLicense = Get-MgUserLicenseDetail -UserId "TESTUSER@TEST.COM"
$userDisabledPlans = $userLicense.ServicePlans | `
Where ProvisioningStatus -eq "Disabled" | `
Select -ExpandProperty ServicePlanId
$e3Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'ENTERPRISEPACK'
$swayServicePlan = $e3Sku.ServicePlans | `
Where ServicePlanName -eq "SWAY"
# Check if the Sway service plan is found
if ($swayServicePlan -ne $null) {
$plansToEnable = @($swayServicePlan.ServicePlanId)
# Remove the Sway service plan from the existing disabled plans
$plansToEnable = $plansToEnable | Where { $userDisabledPlans -notcontains $_ }
$addLicenses = @(
@{
SkuId = $e3Sku.SkuId
DisabledPlans = $userDisabledPlans
EnabledPlans = $plansToEnable
}
)
Set-MgUserLicense -UserId "TESTUSER@TEST.COM" -AddLicenses $addLicenses -RemoveLicenses @()
} else {
Write-Host "Sway service plan not found in the specified E3 SKU."
}
But the script does not seem to work, it does not enable SWAY and I receive the message (blurred user email out):

Does anyone have any ideas as to how I can get this working?