You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MsGraph分配许可证报错:无法将'EMSPREMIUM'转为Edm.Guid

解决Set-MgUserLicense分配许可证时的Edm.Guid转换错误

问题原因

Set-MgUserLicense的SkuId参数要求传入许可证的GUID标识,而非许可证的名称(如EMSPREMIUM)。你直接传入字符串EMSPREMIUM,导致系统无法将其转换为要求的Edm.Guid类型,从而抛出错误。

解决步骤

1. 获取目标许可证的SkuId(GUID)

通过Get-MgSubscribedSku查询已订阅的许可证列表,找到EMSPREMIUM对应的SkuId:

Get-MgSubscribedSku | Select-Object SkuId, SkuPartNumber

运行后会输出类似结果,复制EMSPREMIUM对应的SkuId值:

SkuId                              SkuPartNumber
------                              -------------
xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx EMSPREMIUM
yyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy O365_BUSINESS_PREMIUM

2. 获取需要禁用的服务计划GUID(可选)

如果DisabledPlans使用MFA_PREMIUM名称也出现类似转换错误,需获取其对应的ServicePlanId:

# 替换为上述获取到的EMSPREMIUM的SkuId
Get-MgSubscribedSku -SkuId "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | 
    Select-Object -ExpandProperty ServicePlans | 
    Select-Object ServicePlanId, ServicePlanName

找到MFA_PREMIUM对应的ServicePlanId并复制。

3. 修正后的许可证分配代码

将获取到的GUID填入变量,执行分配操作:

# 替换为EMSPREMIUM的SkuId GUID
$license = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# 替换为MFA_PREMIUM的ServicePlanId GUID
$DisabledPlans = @("zzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz")

$AddLicense = @(
    @{
        SkuId = $license
        DisabledPlans = $DisabledPlans
    }
)

Set-MgUserLicense -UserId $upn -AddLicenses $AddLicense -RemoveLicenses @()

也可以用脚本自动获取GUID,避免手动复制:

# 自动获取EMSPREMIUM的SkuId
$targetSku = Get-MgSubscribedSku | Where-Object { $_.SkuPartNumber -eq "EMSPREMIUM" }
$license = $targetSku.SkuId

# 自动获取MFA_PREMIUM的ServicePlanId
$disabledPlan = $targetSku.ServicePlans | Where-Object { $_.ServicePlanName -eq "MFA_PREMIUM" }
$DisabledPlans = @($disabledPlan.ServicePlanId)

$AddLicense = @(
    @{
        SkuId = $license
        DisabledPlans = $DisabledPlans
    }
)

Set-MgUserLicense -UserId $upn -AddLicenses $AddLicense -RemoveLicenses @()

内容的提问来源于stack exchange,提问作者chocodeea

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 13:35:19