Is there a way to get tags that are associated with an API through Powershell?
The Get-AzApiManagementApi command returns the list of APIs, but tags are not included in its response.
The command Get-AzApiManagementApi
will not return the tags of each API, the workaround is to use Get-AzResource
.
Try the script as below, it returns tags of each API.
$ResourceGroupName = "<resource-group-name>"
$APImg = "<API-Management-service-name>"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $APImg
$Apis = Get-AzApiManagementApi -Context $ApiMgmtContext
foreach($Api in $Apis){
$ApiId = $Api.ApiId
$ApiName = $Api.Name
$tags = (Get-AzResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.ApiManagement/service/apis/tags -ResourceName "$APImg/$ApiId" -ApiVersion 2018-01-01).Name
Write-Host "Tags of" $ApiName : $tags
}