Dela via


Set-AzureRmResourceGroup

Modifies a resource group.

Warning

The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.

Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.

Syntax

SetByResourceGroupName (Default)

Set-AzureRmResourceGroup
    [-Name] <String>
    [-Tag] <Hashtable>
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

SetByResourceGroupId

Set-AzureRmResourceGroup
    [-Tag] <Hashtable>
    [-Id] <String>
    [-ApiVersion <String>]
    [-Pre]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

Description

The Set-AzureRmResourceGroup cmdlet modifies the properties of a resource group. You can use this cmdlet to add, change, or delete the Azure tags applied to a resource group. Specify the Name parameter to identify the resource group and the Tag parameter to modify the tags. You cannot use this cmdlet to change the name of a resource group.

Examples

Example 1: Apply a tag to a resource group

PS C:\>Set-AzureRmResourceGroup -Name "ContosoRG" -Tag @{Department="IT"}

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

Example 2: Add tags to a resource group

PS C:\>$Tags = (Get-AzureRmResourceGroup -Name "ContosoRG").Tags
PS C:\> $Tags
PS C:\> $Tags += @{"Status"="Approved"; "FY2016"=$null}
PS C:\> Set-AzureRmResourceGroup -Name "ContosoRG" -Tag $Tags
PS C:> (Get-AzureRmResourceGroup -Name "ContosoRG").Tags

This example adds a Status tag with a value of Approved and an FY2016 tag to a resource group that has existing tags. Because the tags you specify replace the existing tags, you must include the existing tags in the new tag collection or you will lose them. The first command gets the ContosoRG resource group and uses the dot method to get the value of its Tags property. The command stores the tags in the $Tags variable. The second command gets the tags in the $Tags variable. The third command uses the += assignment operator to add the Status and FY2016 tags to the array of tags in the $Tags variable. The fourth command uses the Tag parameter of Set-AzureRmResourceGroup to apply the tags in the $Tags variable to the ContosoRG resource group. The fifth command gets all of the tags applied to the ContosoRG resource group. The output shows that the resource group has the Department tag and the two new tags, Status and FY2015.

Example 3: Delete all tags for a resource group

PS C:\>Set-AzureRmResourceGroup -Name "ContosoRG" -Tag @{}

This command specifies the Tag parameter with an empty hash table value to delete all tags from the ContosoRG resource group.

Parameters

-ApiVersion

Specifies the API version that is supported by the resource Provider. You can specify a different version than the default version.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

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

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Id

Specifies the ID of the resource group to modify.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:ResourceGroupId, ResourceId

Parameter sets

SetByResourceGroupId
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

Specifies the name of the resource group to modify.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:ResourceGroupName

Parameter sets

SetByResourceGroupName
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Pre

Indicates that this cmdlet considers pre-release API versions when it automatically determines which version to use.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Tag

Key-value pairs in the form of a hash table. For example: @{key0="value0";key1=$null;key2="value2"} A tag is a name-value pair that you can create and apply to resources and resource groups. After you assign tags to resources and groups, you can use the Tag parameter of Get-AzureRmResource and Get-AzureRmResourceGroup to search for resources and groups by tag name or name and value. You can use tags to categorize your resources, such as by department or cost center, or to track notes or comments about the resources. To add or change a tag, you must replace the collection of tags for the resource group. To delete a tag, enter a hash table with all tags currently applied to the resource group, from Get-AzureRmResourceGroup, except for the tag you want to delete. To delete all tags from a resource group, specify an empty hash table: @{}.

Parameter properties

Type:Hashtable
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Tags

Parameter sets

(All)
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

None

Outputs

Microsoft.Azure.Commands.Resources.Models.PSResourceGroup