Set-AzureResource

Set-AzureResource

Changes the properties of an Azure resource.

Syntax

Parameter Set: Default
Set-AzureResource -ApiVersion <String> -Name <String> -ResourceGroupName <String> -ResourceType <String> [-ParentResource <String> ] [-PropertyObject <Hashtable> ] [ <CommonParameters>]

Detailed Description

The Set-AzureResource cmdlet changes the properties of an Azure resource. To use the cmdlet, use the Name, ResourceGroupName, ResourceGroupType, and ParentResourceName 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

-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

ResourceName

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

-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

-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

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. 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.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.

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/site
s" -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:\> $p

Name                           Value
----                           -----
name                           ContosoLabWeb2
storageRecoveryDefaultState    Running
availabilityState              0
trafficManagerHostNames
repositorySiteName             ContosoLabWeb2
runtimeAvailabilityState       0
siteMode                       Limited
runtimeADUser
lastModifiedTimeUtc            3/25/2014 6:00:04 PM
usageState                     0
hostNames                      {contosolabweb2.antares-int.windows-int.net}
adminEnabled                   True
hostNameSslStates              {System.Collections.Generic.Dictionary`2[System.String,System.Object], System.Collect...
runtimeADUserDomain
enabled                        True
deploymentId                   ContosoLabWeb2
selfLink                       https://antpreview2.api.admin-antares-int.windows-int.net:454/20130801/websystems/web...
computeMode                    0
webSpace                       ContosoLabsRG-NorthEuropewebspace
csrs                           {}
siteConfig
integratedSqlAuthEnabled       False
state                          Running
runtimeADUserPassword
serverFarm                     Default1
sslCertificates                {}
cers
contentAvailabilityState       0
enabledHostNames               {contosolabweb2.antares-int.windows-int.net, contosolabweb2.scm.antares-int.windows-i...
windowsAuthEnabled             0
owner
siteProperties                 {[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.Properties

Name                           Value
----                           -----
storageRecoveryDefaultState    Running
availabilityState              0
trafficManagerHostNames
repositorySiteName             ContosoLabWeb2
runtimeAvailabilityState       0
siteMode                       Basic
runtimeADUser
lastModifiedTimeUtc            3/25/2014 6:00:04 PM
usageState                     0
hostNames                      {contosolabweb2.antares-int.windows-int.net}
adminEnabled                   True
hostNameSslStates              {System.Collections.Generic.Dictionary`2[System.String,System.Object], System.Collect...
runtimeADUserDomain
enabled                        True
deploymentId                   ContosoLabWeb2
selfLink                       https://antpreview2.api.admin-antares-int.windows-int.net:454/20130801/websystems/web...
computeMode                    Dedicated
webSpace                       ContosoLabsRG-NorthEuropewebspace
csrs                           {}
siteConfig
integratedSqlAuthEnabled       False
state                          Running
runtimeADUserPassword
serverFarm                     Default2
sslCertificates                {}
cers
contentAvailabilityState       0
enabledHostNames               {contosolabweb2.antares-int.windows-int.net, contosolabweb2.scm.antares-int.windows-i...
windowsAuthEnabled             0
owner
siteProperties                 {[metadata, ], [properties, System.Collections.Generic.List`1[System.Object]], [appSe...
sku                            Basic
name                           ContosoLabWeb2