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

求Azure APIM中获取/关联API版本操作标签的PowerShell命令

Azure APIM 操作标签管理的PowerShell命令

1. 获取指定API版本下操作关联的标签

首先确保已连接Azure账户并切换到目标订阅:

Connect-AzAccount
Select-AzSubscription -SubscriptionId "你的订阅ID"

使用以下命令定位到指定版本的API,并导出所有操作及其关联标签:

# 配置参数
$resourceGroupName = "你的资源组名称"
$apimServiceName = "你的APIM服务实例名称"
$targetApiVersion = "要查询的API版本号(如v2)"
$apiVersionSetId = "目标API版本集的ID" # 可在APIM门户的版本集页面获取

# 获取对应版本的API对象
$targetApi = Get-AzApiManagementApi -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName | 
             Where-Object { $_.ApiVersionSetId -match $apiVersionSetId -and $_.ApiVersion -eq $targetApiVersion }

# 遍历操作并输出标签信息
Get-AzApiManagementOperation -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName -ApiId $targetApi.ApiId | 
ForEach-Object {
    [PSCustomObject]@{
        OperationID = $_.OperationId
        OperationName = $_.Name
        AssociatedTags = ($_.Tags | Select-Object -ExpandProperty Name) -join ", "
    }
}

执行后会以表格形式返回每个操作的ID、名称和关联的标签列表。

2. 关联指定API版本的操作与标签

前提:

  • 目标标签需已存在于APIM实例中(若不存在,先执行下方创建标签命令)
  • 已获取目标API的ApiId和操作的OperationId

创建标签(若需):

$resourceGroupName = "你的资源组名称"
$apimServiceName = "你的APIM服务实例名称"
$tagName = "要创建的标签名称"

New-AzApiManagementTag -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName -Name $tagName -Description "标签描述(可选)"

关联操作与标签:

# 配置参数
$resourceGroupName = "你的资源组名称"
$apimServiceName = "你的APIM服务实例名称"
$apiId = "目标API的ApiId" # 即上面获取的$targetApi.ApiId
$operationId = "要关联标签的操作ID"
$tagName = "目标标签名称"

# 获取标签ID并执行关联
$tagId = (Get-AzApiManagementTag -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName -Name $tagName).TagId
New-AzApiManagementTagResource -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName -ApiId $apiId -OperationId $operationId -TagId $tagId

执行成功后,目标操作会与指定标签建立关联。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 09:40:00