Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

Set-AzureResource

Set-AzureResource

microsoft.azure.commands.resources.dll

Synopsis

Changes the properties of an Azure resource.

Syntax

Set-AzureResource [-ApiVersion] [-PropertyObject] [-Tag] [-Name] [-ResourceGroupName] [-ResourceType] [-ParentResource] [<CommonParameters>]

Detailed Description

The Set-AzureResource cmdlet changes the properties of an Azure resource. To use the cmdlet, use the Name, ResourceGroupName, ResourceGroupType, and ParentResource parameters to identify the resource, and the PropertyObject parameter to specify the new property names and values.If the command succeeds, it returns the resource with the new properties and values.An Azure resource is a user-managed entity, such as an Azure Website or Azure SQL Database. Some resources have properties, which are user-configured values, like sizes and operational modes. You can specify these values when you create the resource, such as by using the New-AzureResource, New-AzureResourceGroup, or New-AzureResourceGroupDeployment cmdlets. And, you can change the properties by using this cmdlet.To get the properties of a resource, use the Get-AzureResource cmdlet to get the resource. Then use the dot method to get the Properties property collection and a particular named property. For example, to get the siteMode property of an object, type (Get-AzureResource -Name MyWebSite -ResourceGroupName RG -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01).Properties.siteMode

Parameters

-ApiVersion <String>

Specifies the API version that is supported by the resource provider. This parameter is required.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-PropertyObject <Hashtable>

Specifies the new property values. Enter a hash table of property names and values. The names and values are case-sensitive.

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Tag <Hashtable[]>

Replaces the tags for the resource with the specified new or predefined tags. To change any resource tag, you must replace the collection of tags for the resource.A "tag" is a name-value pair that you can 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. After you assign tags to resources, you can use the Tag parameters of Get-AzureResource and Get-AzureResourceGroup to search for resources and groups by tag name or name and value.Each tag must have a Name key. It can also have an optional Value key with one value. To specify a new 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 specify a predefined tag, use the Get-AzureTag cmdlet.To delete a tag, enter a hash table with all tags currently applied to the resource (from Get-AzureResource), except for the tag you want to delete. To delete all tags from the resource, enter an empty hash table (-Tag @{}).

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Name <String>

Specifies the name of the Azure resource. The name is case-sensitive. Wildcards are not permitted. This value identifies the resource. You cannot use this cmdlet to change the resource name.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-ResourceGroupName <String>

Specifies the name of the resource group of the resource. Wildcards are not permitted. This value identifies the resource. You cannot use this cmdlet to change the resource group of a resource.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-ResourceType <String>

Specifies the resource type. Wildcards are not permitted. This value identifies the resource. You cannot use this cmdlet to change the resource type.

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-ParentResource <String>

Specifies the names of the logical parent of a resource. Enter the fully qualified name of the parent resource, such as " Microsoft.Sql/servers/ContosoSQLSvr". Wildcards are not permitted. This value identifies the resource. You cannot use this cmdlet to change the resource parent.Use this parameter when the resource is a type that has parents. For example, every SQL Azure database has a parent SQL Azure database server. A resource group is not a parent of its resources.

Aliases

None

Required?

false

Position

named

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

Input Type

None

Return Type

Microsoft.Azure.Commands.ResourceManager.Models.PSResource

Notes

The Set-AzureResource cmdlet is included in the Azure Resource Manager module beginning in module version 0.8.0.

Examples

-------------------------- Example 1: Change the properties of a resource --------------------------

This example shows how to change the properties of an Azure resource. In this case, we'll shift a web site from one server farm to another. To do that, we have to change the web site properties to be compatible with the new server farm.

PS C:\> The first command uses the Get-AzureResource cmdlet to get the ContosoLabWeb2 web site. The command saves the resource in the $r variable.
PS C:\>$r = Get-AzureResource -Name ContosoLabWeb2 -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01

The second command saves the Properties property (and its properties) of the resource in the $p variable. The Properties object is a Dictionary, but because it is convertible to a hash table, you can use it as the value of the PropertyObject parameter of Set-AzureResource without casting.
PS C:\>$p = $r.Properties

The third command displays the properties in the $p variable.
PS C:\>$pName                           Value----                           -----name                           ContosoLabWeb2storageRecoveryDefaultState    RunningavailabilityState              0trafficManagerHostNamesrepositorySiteName             ContosoLabWeb2runtimeAvailabilityState       0siteMode                       LimitedruntimeADUserlastModifiedTimeUtc            3/25/2014 6:00:04 PMusageState                     0hostNames                      {contosolabweb2.antares-int.windows-int.net}adminEnabled                   TruehostNameSslStates              {System.Collections.Generic.Dictionary`2[System.String,System.Object], System.Collect...runtimeADUserDomainenabled                        TruedeploymentId                   ContosoLabWeb2selfLink                       https://antpreview2.api.admin-antares-int.windows-int.net:454/20130801/websystems/web...computeMode                    0webSpace                       ContosoLabsRG-NorthEuropewebspacecsrs                           {}siteConfigintegratedSqlAuthEnabled       Falsestate                          RunningruntimeADUserPasswordserverFarm                     Default1sslCertificates                {}cerscontentAvailabilityState       0enabledHostNames               {contosolabweb2.antares-int.windows-int.net, contosolabweb2.scm.antares-int.windows-i...windowsAuthEnabled             0ownersiteProperties                 {[metadata, ], [properties, System.Collections.Generic.List`1[System.Object]], [appSe...sku                            Free

The fourth command is actually a series of commands (delimited by semi-colons) that change the values of the properties in the $p variable.
PS C:\>$p.siteMode = "Basic"; $p.sku = "Basic"; $p.computeMode = "Dedicated"; $p.serverFarm = "Default2"

The fifth command uses the Set-AzureResource cmdlet to change the change the properties of the ContosoLabWeb2 web site. The value of the PropertyObject parameter is the $p variable that contains the Properties object and the new values. The command saves the output (the updated resource) in the $r2 variable.
PS C:\>$r2 = Set-AzureResource -Name ContosoLabWeb2 -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01 -PropertyObject $p

The sixth command displays the Properties property of the resource in the $r2 variable. You can see that the properties have the new values.
PS C:\>$r2.PropertiesName                           Value----                           -----storageRecoveryDefaultState    RunningavailabilityState              0trafficManagerHostNamesrepositorySiteName             ContosoLabWeb2runtimeAvailabilityState       0siteMode                       BasicruntimeADUserlastModifiedTimeUtc            3/25/2014 6:00:04 PMusageState                     0hostNames                      {contosolabweb2.antares-int.windows-int.net}adminEnabled                   TruehostNameSslStates              {System.Collections.Generic.Dictionary`2[System.String,System.Object], System.Collect...runtimeADUserDomainenabled                        TruedeploymentId                   ContosoLabWeb2selfLink                       https://antpreview2.api.admin-antares-int.windows-int.net:454/20130801/websystems/web...computeMode                    DedicatedwebSpace                       ContosoLabsRG-NorthEuropewebspacecsrs                           {}siteConfigintegratedSqlAuthEnabled       Falsestate                          RunningruntimeADUserPasswordserverFarm                     Default2sslCertificates                {}cerscontentAvailabilityState       0enabledHostNames               {contosolabweb2.antares-int.windows-int.net, contosolabweb2.scm.antares-int.windows-i...windowsAuthEnabled             0ownersiteProperties                 {[metadata, ], [properties, System.Collections.Generic.List`1[System.Object]], [appSe...sku                            Basicname                           ContosoLabWeb2

-------------------------- Example 2: Apply a tag to a resource --------------------------

This command uses the Tag parameter to add a CostCenter tag with a value of "Sales" to a resource that did not have any existing tags.

PS C:\>Get-AzureResource -Name ContosoLabWeb2 -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01 -Tag @{Name="CostCenter";Value="Sales"}

-------------------------- Example 3: Add tags to a resource --------------------------

This command adds a "Status" tag with a value of "Approved" and an "FY2016" tag to a resource 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.

PS C:\>$tags = (Get-AzureResource -Name ContosoWeb -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01).Tags

PS C:\>$tags


Tags: 

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


PS C:\>$tags += @{Name="Status";Value="Approved"}, @{Name="FY2016"}

PS C:\>Set-AzureResource -Name ContosoWeb -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01 -Tag $tags

PS C:>(Get-AzureResource -Name ContosoWeb -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01).Tags


Tags: 

      Name        Value
      ====        ======
      Department  IT
      Status      Approved
      FY2016

-------------------------- Example 4: Delete all tags --------------------------

This command uses the Tag parameter and an empty hash table value to delete all tags from a resource.

PS C:\>Get-AzureResource -Name ContosoLabWeb2 -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2004-04-01 -Tag @{}

Online Version