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

Azure服务主体添加name=value标签遇MissingSubscription错误求助

解决Azure Service Principal添加标签的问题

你遇到的错误是因为Set-AzResource仅适用于Azure资源管理器(ARM)订阅范围内的资源(如虚拟机、存储账户等),而Service Principal是Azure AD的租户级对象,不属于任何订阅,因此该命令无法对其操作。以下是正确的操作方法:

PowerShell 操作步骤

  1. 获取目标Service Principal对象:
$sp = Get-AzADServicePrincipal -DisplayName "tempdelete"
  1. 准备标签(Azure AD的Service Principal标签为字符串数组,每个元素格式为key=value):

    • 若要覆盖所有现有标签:
    $tags = @("name=value")
    
    • 若要保留现有标签并添加新标签:
    $existingTags = $sp.Tags
    $newTags = $existingTags + "name=value"
    
  2. 执行标签更新:

Update-AzADServicePrincipal -ObjectId $sp.Id -Tags $newTags

Azure CLI 操作步骤

使用你提到的命令即可直接添加标签,支持单次添加或多次添加:

  • 单次添加标签:
az ad sp update --id <service_principal_id> --add tags "name=value"
  • 添加多个标签:
az ad sp update --id <service_principal_id> --add tags "name1=value1" --add tags "name2=value2"

验证标签是否生效

执行以下命令查看Service Principal的标签:

Get-AzADServicePrincipal -ObjectId $sp.Id | Select-Object DisplayName, Tags

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 01:52:17