使用标记对 Azure 资源和管理层次结构进行组织Use tags to organize your Azure resources and management hierarchy

可将标记应用到 Azure 资源、资源组和订阅,以便有条理地将它们组织成分类。You apply tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy. 每个标记均由名称和值对组成。Each tag consists of a name and a value pair. 例如,可以对生产中的所有资源应用名称“Environment”和值“Production”。For example, you can apply the name "Environment" and the value "Production" to all the resources in production.

重要

标记名称对于操作不区分大小写。Tag names are case-insensitive for operations. 系统会更新或检索具有标记名称的标记,而不考虑大小写。A tag with a tag name, regardless of casing, is updated or retrieved. 但是,资源提供程序可能会保留为标记名称提供的大小写。However, the resource provider might keep the casing you provide for the tag name. 你将在成本报表中看到该大小写。You'll see that casing in cost reports.

标记值区分大小写。Tag values are case-sensitive.

备注

本文介绍如何删除设备或服务中的个人数据,并且可为 GDPR 下的任务提供支持。This article provides steps for how to delete personal data from the device or service and can be used to support your obligations under the GDPR. 如需关于 GDPR 的常规信息,请参阅服务信任门户的 GDPR 部分If you're looking for general info about GDPR, see the GDPR section of the Service Trust portal.

所需访问权限Required access

若要将标记应用到资源,必须对 Microsoft.Resources/tags 资源类型拥有写入权限。To apply tags to a resource, you must have write access to the Microsoft.Resources/tags resource type. 标记参与者角色可让你将标记应用到实体,无需访问该实体本身。The Tag Contributor role lets you apply tags to an entity without having access to the entity itself. 目前,标记参与者角色无法通过门户将标记应用到资源或资源组。Currently, the tag contributor role can't apply tags to resources or resource groups through the portal. 该角色可以通过门户将标记应用到订阅。It can apply tags to subscriptions through the portal. 它支持通过 PowerShell 和 REST API 执行所有标记操作。It supports all tag operations through PowerShell and REST API.

参与者角色还授予对任何实体应用标记所需的访问权限。The Contributor role also grants the required access to apply tags to any entity. 要将标记仅应用于一种资源类型,请使用该资源的参与者角色。To apply tags to only one resource type, use the contributor role for that resource. 例如,要将标记应用到虚拟机,请使用虚拟机参与者For example, to apply tags to virtual machines, use the Virtual Machine Contributor.

PowerShellPowerShell

应用标记Apply tags

Azure PowerShell 提供两个用于应用标记的命令 - New-AzTagUpdate-AzTagAzure PowerShell offers two commands for applying tags - New-AzTag and Update-AzTag. 必须安装 Az.Resources 模块 1.12.0 或更高版本。You must have the Az.Resources module 1.12.0 or later. 可以使用 Get-Module Az.Resources 检查自己的版本。You can check your version with Get-Module Az.Resources. 可以安装该模块,或安装 Azure PowerShell 3.6.1 或更高版本。You can install that module or install Azure PowerShell 3.6.1 or later.

New-AzTag 替换资源、资源组或订阅中的所有标记。The New-AzTag replaces all tags on the resource, resource group, or subscription. 调用该命令时,请传入要标记的实体的资源 ID。When calling the command, pass in the resource ID of the entity you wish to tag.

以下示例将一组标记应用到存储帐户:The following example applies a set of tags to a storage account:

$tags = @{"Dept"="Finance"; "Status"="Normal"}
$resource = Get-AzResource -Name demoStorage -ResourceGroup demoGroup
New-AzTag -ResourceId $resource.id -Tag $tags

该命令完成后,会发现该资源带有两个标记。When the command completes, notice that the resource has two tags.

Properties :
        Name    Value
        ======  =======
        Dept    Finance
        Status  Normal

如果再次运行该命令(但这一次使用不同的标记),则会发现以前的标记已删除。If you run the command again but this time with different tags, notice that the earlier tags are removed.

$tags = @{"Team"="Compliance"; "Environment"="Production"}
New-AzTag -ResourceId $resource.id -Tag $tags
Properties :
        Name         Value
        ===========  ==========
        Environment  Production
        Team         Compliance

若要将标记添加到已经有标记的资源,请使用 Update-AzTag。To add tags to a resource that already has tags, use Update-AzTag. 将 -Operation 参数设置为 Merge 。Set the -Operation parameter to Merge.

$tags = @{"Dept"="Finance"; "Status"="Normal"}
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge

你会发现,已将两个新标记添加到了两个现有标记中。Notice that the two new tags were added to the two existing tags.

Properties :
        Name         Value
        ===========  ==========
        Status       Normal
        Dept         Finance
        Team         Compliance
        Environment  Production

每个标记名称只能有一个值。Each tag name can have only one value. 如果为标记提供新值,则即使使用合并操作,也会替换旧值。If you provide a new value for a tag, the old value is replaced even if you use the merge operation. 以下示例将 Status 标记从 Normal 更改为 Green。The following example changes the Status tag from Normal to Green.

$tags = @{"Status"="Green"}
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
Properties :
        Name         Value
        ===========  ==========
        Status       Green
        Dept         Finance
        Team         Compliance
        Environment  Production

将 -Operation 参数设置为 Replace 时,会将现有标记替换为新的标记集 。When you set the -Operation parameter to Replace, the existing tags are replaced by the new set of tags.

$tags = @{"Project"="ECommerce"; "CostCenter"="00123"; "Team"="Web"}
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Replace

资源中只会保留新标记。Only the new tags remain on the resource.

Properties :
        Name        Value
        ==========  =========
        CostCenter  00123
        Team        Web
        Project     ECommerce

相同的命令也适用于资源组或订阅。The same commands also work with resource groups or subscriptions. 传入要标记的资源组或订阅的标识符。You pass in the identifier for the resource group or subscription you want to tag.

若要将一组新标记添加到资源组,请使用:To add a new set of tags to a resource group, use:

$tags = @{"Dept"="Finance"; "Status"="Normal"}
$resourceGroup = Get-AzResourceGroup -Name demoGroup
New-AzTag -ResourceId $resourceGroup.ResourceId -tag $tags

若要更新资源组的标记,请使用:To update the tags for a resource group, use:

$tags = @{"CostCenter"="00123"; "Environment"="Production"}
$resourceGroup = Get-AzResourceGroup -Name demoGroup
Update-AzTag -ResourceId $resourceGroup.ResourceId -Tag $tags -Operation Merge

若要将一组新标记添加到订阅,请使用:To add a new set of tags to a subscription, use:

$tags = @{"CostCenter"="00123"; "Environment"="Dev"}
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
New-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags

若要更新订阅的标记,请使用:To update the tags for a subscription, use:

$tags = @{"Team"="Web Apps"}
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
Update-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags -Operation Merge

一个资源组中可能有多个同名资源。You may have more than one resource with the same name in a resource group. 在这种情况下,可以通过以下命令设置每个资源:In that case, you can set each resource with the following commands:

$resource = Get-AzResource -ResourceName sqlDatabase1 -ResourceGroupName examplegroup
$resource | ForEach-Object { Update-AzTag -Tag @{ "Dept"="IT"; "Environment"="Test" } -ResourceId $_.ResourceId -Operation Merge }

列出标记List tags

若要获取资源、资源组或订阅的标记,请使用 Get-AzTag 命令并传入实体的资源 ID。To get the tags for a resource, resource group, or subscription, use the Get-AzTag command and pass in the resource ID for the entity.

若要查看资源的标记,请使用:To see the tags for a resource, use:

$resource = Get-AzResource -Name demoStorage -ResourceGroup demoGroup
Get-AzTag -ResourceId $resource.id

若要查看资源组的标记,请使用:To see the tags for a resource group, use:

$resourceGroup = Get-AzResourceGroup -Name demoGroup
Get-AzTag -ResourceId $resourceGroup.ResourceId

若要查看订阅的标记,请使用:To see the tags for a subscription, use:

$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
Get-AzTag -ResourceId "/subscriptions/$subscription"

按标记列出List by tag

若要获取具有特定标记名称和值的资源,请使用:To get resources that have a specific tag name and value, use:

(Get-AzResource -Tag @{ "CostCenter"="00123"}).Name

若要获取具有特定标记名称和任意标记值的资源,请使用:To get resources that have a specific tag name with any tag value, use:

(Get-AzResource -TagName "Dept").Name

若要获取具有特定标记名称和值的资源组,请使用:To get resource groups that have a specific tag name and value, use:

(Get-AzResourceGroup -Tag @{ "CostCenter"="00123" }).ResourceGroupName

删除标记Remove tags

若要删除特定的标记,请使用 Update-AzTag 并将 -Operation 设置为 Delete 。To remove specific tags, use Update-AzTag and set -Operation to Delete. 传入要删除的标记。Pass in the tags you want to delete.

$removeTags = @{"Project"="ECommerce"; "Team"="Web"}
Update-AzTag -ResourceId $resource.id -Tag $removeTags -Operation Delete

指定的标记随即被删除。The specified tags are removed.

Properties :
        Name        Value
        ==========  =====
        CostCenter  00123

若要删除所有标记,请使用 Remove-AzTag 命令。To remove all tags, use the Remove-AzTag command.

$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
Remove-AzTag -ResourceId "/subscriptions/$subscription"

Azure CLIAzure CLI

应用标记Apply tags

将标记添加到资源组或资源时,可以覆盖现有的标记,或将新标记追加到现有标记之后。When adding tags to a resource group or resource, you can either overwrite the existing tags or append new tags to existing tags.

若要覆盖资源的标记,请使用:To overwrite the tags on a resource, use:

az resource tag --tags 'Dept=IT' 'Environment=Test' -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks"

若将标记追加到资源的现有标记之后,请使用:To append a tag to the existing tags on a resource, use:

az resource update --set tags.'Status'='Approved' -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks"

若要覆盖资源组的现有标记,请使用:To overwrite the existing tags on a resource group, use:

az group update -n examplegroup --tags 'Environment=Test' 'Dept=IT'

若要将标记追加到资源组的现有标记之后,请使用:To append a tag to the existing tags on a resource group, use:

az group update -n examplegroup --set tags.'Status'='Approved'

目前,Azure CLI 没有用于将标记应用于订阅的命令。Currently, Azure CLI doesn't have a command for applying tags to subscriptions. 但是,可以使用 CLI 来部署将标记应用于订阅的 ARM 模板。However, you can use CLI to deploy an ARM template that applies the tags to a subscription. 请参阅将标记应用于资源组或订阅See Apply tags to resource groups or subscriptions.

列出标记List tags

若要查看资源的现有标记,请使用:To see the existing tags for a resource, use:

az resource show -n examplevnet -g examplegroup --resource-type "Microsoft.Network/virtualNetworks" --query tags

若要查看资源组的现有标记,请使用:To see the existing tags for a resource group, use:

az group show -n examplegroup --query tags

该脚本返回以下格式:That script returns the following format:

{
  "Dept"        : "IT",
  "Environment" : "Test"
}

按标记列出List by tag

若要获取具有特定标记和值的所有资源,请使用 az resource listTo get all the resources that have a particular tag and value, use az resource list:

az resource list --tag Dept=Finance

若要获取具有特定标记的资源组,请使用 az group listTo get resource groups that have a specific tag, use az group list:

az group list --tag Dept=IT

处理空格Handling spaces

如果标记名称或值包含空格,则必须执行几个额外的步骤。If your tag names or values include spaces, you must take a couple of extra steps. 下面的示例在标记可能包含空格时将资源组中的所有标记应用于其资源。The following example applies all tags from a resource group to its resources when the tags may contain spaces.

jsontags=$(az group show --name examplegroup --query tags -o json)
tags=$(echo $jsontags | tr -d '{}"' | sed 's/: /=/g' | sed "s/\"/'/g" | sed 's/, /,/g' | sed 's/ *$//g' | sed 's/^ *//g')
origIFS=$IFS
IFS=','
read -a tagarr <<< "$tags"
resourceids=$(az resource list -g examplegroup --query [].id --output tsv)
for id in $resourceids
do
  az resource tag --tags "${tagarr[@]}" --id $id
done
IFS=$origIFS

模板Templates

可以在使用资源管理器模板进行部署期间标记资源、资源组和订阅。You can tag resources, resource groups, and subscriptions during deployment with a Resource Manager template.

应用值Apply values

以下示例部署具有三个标记的存储帐户。The following example deploys a storage account with three tags. 两个标记(DeptEnvironment)设置为文本值。Two of the tags (Dept and Environment) are set to literal values. 一个标记 (LastDeployed) 设置为默认值为当前日期的参数。One tag (LastDeployed) is set to a parameter that defaults to the current date.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "utcShort": {
            "type": "string",
            "defaultValue": "[utcNow('d')]"
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        }
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage', uniqueString(resourceGroup().id))]",
            "location": "[parameters('location')]",
            "tags": {
                "Dept": "Finance",
                "Environment": "Production",
                "LastDeployed": "[parameters('utcShort')]"
            },
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        }
    ]
}

应用对象Apply an object

可以定义一个存储多个标记的对象参数,并将该对象应用于标记元素。You can define an object parameter that stores several tags, and apply that object to the tag element. 此方法比上一个示例更灵活,因为对象可以使用不同的属性。This approach provides more flexibility than the previous example because the object can have different properties. 对象中的每个属性会成为资源的单独标记。Each property in the object becomes a separate tag for the resource. 以下示例有一个名为 tagValues 的参数,该标记应用于标记元素。The following example has a parameter named tagValues that is applied to the tag element.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "tagValues": {
            "type": "object",
            "defaultValue": {
                "Dept": "Finance",
                "Environment": "Production"
            }
        }
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage', uniqueString(resourceGroup().id))]",
            "location": "[parameters('location')]",
            "tags": "[parameters('tagValues')]",
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        }
    ]
}

应用 JSON 字符串Apply a JSON string

要将多个值存储在单个标记中,请应用表示这些值的 JSON 字符串。To store many values in a single tag, apply a JSON string that represents the values. 整个 JSON 字符串存储为一个标记,该标记不能超过 256 个字符。The entire JSON string is stored as one tag that can't exceed 256 characters. 以下示例有一个名为 CostCenter 的标记,其中包含 JSON 字符串中的多个值:The following example has a single tag named CostCenter that contains several values from a JSON string:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        }
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage', uniqueString(resourceGroup().id))]",
            "location": "[parameters('location')]",
            "tags": {
                "CostCenter": "{\"Dept\":\"Finance\",\"Environment\":\"Production\"}"
            },
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        }
    ]
}

应用资源组中的标记Apply tags from resource group

若要将资源组中的标记应用于资源,请使用 resourceGroup() 函数。To apply tags from a resource group to a resource, use the resourceGroup() function. 获取标记值时,请使用 tags[tag-name] 语法而不是 tags.tag-name 语法,因为有些字符在点表示法中无法正确解析。When getting the tag value, use the tags[tag-name] syntax instead of the tags.tag-name syntax, because some characters aren't parsed correctly in the dot notation.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        }
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage', uniqueString(resourceGroup().id))]",
            "location": "[parameters('location')]",
            "tags": {
                "Dept": "[resourceGroup().tags['Dept']]",
                "Environment": "[resourceGroup().tags['Environment']]"
            },
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        }
    ]
}

将标记应用到多个资源组或订阅Apply tags to resource groups or subscriptions

可以通过部署 Microsoft.Resources/tags 资源类型,将标记添加到资源组或订阅。You can add tags to a resource group or subscription by deploying the Microsoft.Resources/tags resource type. 标记会应用到此部署的目标资源组或订阅。The tags are applied to the target resource group or subscription for the deployment. 每次部署模板时,都要替换以前应用的任何标记。Each time you deploy the template you replace any tags there were previously applied.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "tagName": {
            "type": "string",
            "defaultValue": "TeamName"
        },
        "tagValue": {
            "type": "string",
            "defaultValue": "AppTeam1"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/tags",
            "name": "default",
            "apiVersion": "2019-10-01",
            "dependsOn": [],
            "properties": {
                "tags": {
                    "[parameters('tagName')]": "[parameters('tagValue')]"
                }
            }
        }
    ]
}

若要将标记应用到资源组,请使用 PowerShell 或 Azure CLI。To apply the tags to a resource group, use either PowerShell or Azure CLI. 部署到要标记的资源组。Deploy to the resource group that you want to tag.

New-AzResourceGroupDeployment -ResourceGroupName exampleGroup -TemplateFile https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
az deployment group create --resource-group exampleGroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json

若要将标记应用到订阅,请使用 PowerShell 或 Azure CLI。To apply the tags to a subscription, use either PowerShell or Azure CLI. 部署到要标记的订阅。Deploy to the subscription that you want to tag.

New-AzSubscriptionDeployment -name tagresourcegroup -Location chinanorth2 -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
az deployment sub create --name tagresourcegroup --location chinanorth2 --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json

有关订阅部署的详细信息,请参阅在订阅级别创建资源组和资源For more information about subscription deployments, see Create resource groups and resources at the subscription level.

以下模板将对象中的标记添加到资源组或订阅。The following template adds the tags from an object to either a resource group or subscription.

"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "tags": {
            "type": "object",
            "defaultValue": {
                "TeamName": "AppTeam1",
                "Dept": "Finance",
                "Environment": "Production"
            }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/tags",
            "name": "default",
            "apiVersion": "2019-10-01",
            "dependsOn": [],
            "properties": {
                "tags": "[parameters('tags')]"
            }
        }
    ]
}

门户Portal

  1. 若要查看资源或资源组的标记,请在概述中查找现有标记。To view the tags for a resource or a resource group, look for existing tags in the overview. 如果以前未应用标记,则该列表为空。If you have not previously applied tags, the list is empty.

    查看资源或资源组的标记

  2. 若要添加标记,请选择“单击此处以添加标记” 。To add a tag, select Click here to add tags.

  3. 提供名称和值。Provide a name and value. 选择“+”以添加标记。Select + to add the tag.

    添加标记

  4. 根据需要继续添加标记。Continue adding tags as needed. 完成后,选择“保存” 。When done, select Save.

    保存标记

  5. 标记现已显示在概述中。The tags are now displayed in the overview.

    显示标记

  6. 若要添加或删除标记,请选择“更改” 。To add or delete a tag, select change.

  7. 若要删除标记,请选择回收站图标。To delete a tag, select the trash icon. 然后选择“保存” 。Then, select Save.

    删除标记

将标记批量分配到多个资源:To bulk assign tags to multiple resources:

  1. 从任意资源列表中,选中想要分配标记的资源的复选框。From any list of resources, select the checkbox for the resources you want to assign the tag.

    选择多个资源

  2. 选择“分配标记” Select Assign tags

    分配标记

  3. 在每个名称和值后,选择“+”。After each name and value, select +. 完成后,选择“分配” 。When done, select Assign.

    选择“分配”

查看所有具有标记的资源:To view all resources with a tag:

  1. 在 Azure 门户菜单中,选择“所有服务” 。On the Azure portal menu, select All services. 选择“常规” ,然后选择“标记” 。Select General, then Tags.

    按标记查找

  2. 选择用于查看资源的标记。Select the tag for viewing resources.

    选择标记

  3. 此时会显示所有具有该标记的资源。All resources with that tag are displayed.

    按标记查看资源

  4. 将视图固定到仪表板可实现快速访问。For quick access, pin the view to the dashboard.

    固定到仪表板

  5. 仪表板中提供该视图。The view is available from the dashboard.

    仪表板

REST APIREST API

若要通过 Azure REST API 处理标记,请使用:To work with tags through the Azure REST API, use:

继承标记Inherit tags

应用到资源组或订阅的标记不会由资源继承。Tags applied to the resource group or subscription aren't inherited by the resources. 若要将订阅或资源组中的标记应用到资源,请参阅 Azure 策略 - 标记To apply tags from a subscription or resource group to the resources, see Azure Policies - tags.

标记和计费Tags and billing

可使用标记对计费数据进行分组。You can use tags to group your billing data. 例如,如果针对不同组织运行多个 VM,可以使用标记根据成本中心对使用情况进行分组。For example, if you're running multiple VMs for different organizations, use the tags to group usage by cost center. 还可使用标记根据运行时环境(例如,在生产环境中运行的 VM 的计费使用情况)对成本进行分类。You can also use tags to categorize costs by runtime environment, such as the billing usage for VMs running in the production environment.

可以通过使用情况逗号分隔值 (CSV) 文件检索有关标记的信息。You can retrieve information about tags through the usage comma-separated values (CSV) file. 可以从 Azure 帐户门户下载使用情况文件。You download the usage file from the Azure account portal.

有关 REST API 操作,请参阅 Azure 计费 REST API 参考For REST API operations, see Azure Billing REST API Reference.

限制Limitations

以下限制适用于标记:The following limitations apply to tags:

  • 并非所有资源类型都支持标记。Not all resource types support tags. 若要确定是否可以将标记应用到资源类型,请参阅 Azure 资源的标记支持To determine if you can apply a tag to a resource type, see Tag support for Azure resources.

  • 每个资源、资源组和订阅最多可以有 50 个标记名称/值对。Each resource, resource group, and subscription can have a maximum of 50 tag name/value pairs. 如果需要应用的标记超过最大允许数量,请使用 JSON 字符串作为标记值。If you need to apply more tags than the maximum allowed number, use a JSON string for the tag value. JSON 字符串可以包含多个应用于单个标记名称的值。The JSON string can contain many values that are applied to a single tag name. 一个资源组或订阅可以包含多个资源,这些资源每个都有 50 个标记名称/值对。A resource group or subscription can contain many resources that each have 50 tag name/value pairs.

  • 标记名称不能超过 512 个字符,标记值不能超过 256 个字符。The tag name is limited to 512 characters, and the tag value is limited to 256 characters. 对于存储帐户,标记名称不能超过 128 个字符,标记值不能超过 256 个字符。For storage accounts, the tag name is limited to 128 characters, and the tag value is limited to 256 characters.

  • 不能将标记应用到云服务等经典资源。Tags can't be applied to classic resources such as Cloud Services.

  • 标记名称不能包含以下字符:<>%&\?/Tag names can't contain these characters: <, >, %, &, \, ?, /

    备注

    目前,Azure DNS 区域和流量管理器服务也不允许在标记中使用空格。Currently, Azure DNS zones and Traffic Manager services also don't allow the use of spaces in the tag.

    Azure Front Door 不支持在标记名称中使用 #Azure Front Door doesn't support the use of # in the tag name.

    Azure 自动化和 Azure CDN 仅支持资源上的 15 个标记。Azure Automation and Azure CDN only support 15 tags on resources.

后续步骤Next steps