共用方式為


Set-AzureResourceGroup

Set-AzureResourceGroup

Sets the properties of a resource group.

Syntax

Parameter Set: Default
Set-AzureResourceGroup [-Name] <String> [-Tag] <Hashtable[]> [-Profile <AzureProfile> ] [ <CommonParameters>]

Detailed Description

The Set-AzureResourceGroup cmdlet changes the properties of an Azure resource group. You can use this cmdlet to add, change, or delete the Azure tags applied to a resource group. You can use the Name parameter to identify the resource group, and you can use the Tag parameter to change the tags. You cannot use this cmdlet to change the name of a resource group. For more information about Azure resources and Azure resource groups, see the New-AzureResourceGroup cmdlet.

Parameters

-Name<String>

Specifies the name of the resource group to set.

Aliases

ResourceGroupName

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Profile<AzureProfile>

Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Tag<Hashtable[]>

Specifies the tags for the resource group. A tag is a name/value pair that you can create and apply to resources and resource groups.

Use tags to categorize your resources, such as by department or cost center, or to track notes or comments about the resources. Each tag must have a Name key, and it can also have an optional Value key with one value.

To specify a tag, use a hash table, such as @{Name="FY2015"} or @{Name="Department";Value="IT"}. To specify multiple tags, use commas to separate the hash tables, such as -Tag @{Name="FY2015"}, @{Name="Department";Value="IT"}.

To add or change a single tag, you must replace the collection of tags for the resource group. After you assign tags to resources and groups, you can use the Tag parameter of the Get-AzureResource and Get-AzureResourceGroup cmdlets to search for resources and resource groups by tag name or by tag name/value pair.

To delete a tag, use the Get-AzureResourceGroup cmdlet to get all of the tags applied to a resource group. Then use Set-AzureResourceGroup with the Tag parameter to add a hash table with all of the tags currently applied to the resource group except for the tag that you want to delete. To delete all of the tags from a resource group, specify an empty hash table (-Tag @{}).

Aliases

Tags

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You can pipe input to the cmdlet by property name, but not by value.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Azure.Commands.Resources.Models.PSResourceGroup

    This cmdlet returns the resource group that it modifies.

Examples

Example 1: Apply a tag to a resource group

This command applies a tag named Department with a value of IT to a resource group that has no existing tags.

Set-AzureResourceGroup -Name "ContosoResourceGroup" -Tag @{Name="Department";Value="IT"}

Example 2: Add tags to a resource group

This command adds a tag named Status with a value of Approved and a tag named FY2016 to a resource group that has existing tags. Because this command overwrites any existing tags, the command includes the existing tags in the new tag collection so that they are not overwritten.

The first command uses the Get-AzureResourceGroup cmdlet to get all existing tags of the resource group named ContosoResourceGroup, and uses the dot operator (.) to get the value of its Tags property. It then stores the existing tags in the $Tags variable.

The second command displays the name and value for each tag in $Tags.

The third command uses the assignment by addition operator (+=) to add the Status and FY2016 tags to the collection of tags in $Tags.

The fourth command uses the Tag parameter of Set-AzureResourceGroup to apply the tags in $Tags to ContosoResourceGroup.

The final command displays all of the tags applied to ContosoResourceGroup. The output displays the Department tag and the two new tags, Status and FY2015.

$Tags = (Get-AzureResourceGroup -Name ContosoResourceGroup).Tags
PS C:\>$Tags

Tags: 

      Name        Value
      ====        ======
      Department  IT

PS C:\>$Tags += @{Name="Status";Value="Approved"}, @{Name="FY2016"}
PS C:\>Set-AzureResourceGroup -Name ContosoResourceGroup -Tag $Tags
PS C:>(Get-AzureResourceGroup -Name ContosoResourceGroup).Tags

Tags: 

      Name        Value
      ====        ======
      Department  IT

      Status      Approved
      FY2016

Example 3: Delete all tags

This command deletes all of the tags from the resource group named ContosoResourceGroup. It specifies the Tag parameter with an empty hash table value to overwrite the existing tag collection.

Set-AzureResourceGroup -Name "ContosoResourceGroup" -Tag @{}

Get-AzureResource

Get-AzureResourceGroup

New-AzureResourceGroup

Remove-AzureResourceGroup