編輯

共用方式為


Update-AzTag

Selectively updates the set of tags on a resource or subscription.

Syntax

Update-AzTag
      [-ResourceId] <String>
      [-Tag] <Hashtable>
      [-Operation] <TagPatchOperation>
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

The Update-AzTag cmdlet with a ResourceId selectively updates the set of tags on a resource or subscription. This operation allows replacing, merging or selectively deleting tags on the specified resource or subscription. The specified entity can have a maximum of 50 tags at the end of the operation. The 'replace' option replaces the entire set of existing tags with a new set. The 'merge' option allows adding tags with new names and updating the values of tags with existing names. The 'delete' option allows selectively deleting tags based on given names or name/value pairs.

Examples

Example 1: Selectively updates the set of tags on a subscription with "Merge" Operation

$mergedTags = @{"key1"="value1"; "key3"="value3";}
Update-AzTag -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -Tag $mergedTags -Operation Merge

Id         : {Id}
Name       : {Name}
Type       : {Type}
Properties :
             Name     Value
             =======  =========
             key1     value1
             key2     value2
             key3     value3

This command Merges the set of tags on the subscription with "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".

Example 2: Selectively updates the set of tags on a subscription with "Replace" Operation

$replacedTags = @{"key1"="value1"; "key3"="value3";}
Update-AzTag -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -Tag $replacedTags -Operation Replace

Id         : {Id}
Name       : {Name}
Type       : {Type}
Properties :
             Name     Value
             =======  =========
             key1     value1
             key3     value3

This command Replaces the set of tags on the subscription with "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".

Example 3: Selectively updates the set of tags on a subscription with "Delete" Operation

$deletedTags = @{"key1"="value1"}
Update-AzTag -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -Tag $deletedTags -Operation Delete

Id         : {Id}
Name       : {Name}
Type       : {Type}
Properties :
             Name     Value
             =======  =========
             key3     value3

This command Deletes the set of tags on the subscription with "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Operation

The update operation. Options are Merge, Replace and Delete.

Type:TagPatchOperation
Accepted values:Merge, Replace, Delete
Position:2
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-ResourceId

The resource identifier for the tagged entity. A resource, a resource group or a subscription may be tagged.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Tag

The set of tags to use for update.

Type:Hashtable
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

TagPatchOperation

Hashtable

Outputs

PSTagResource