Set-AzResource
Modifies an existing resource. Use this cmdlet to update properties of a resource that has already been deployed.
SYNOPSIS
Updates an Azure resource.
SYNTAX
Set-AzResource [-Name] <String> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]Set-AzResource [-ResourceGroupName] <String> [-Name] <String> [-ResourceType] <String> [-ApiVersion] <String> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]Set-AzResource [-InputObject] <PSObject> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]DESCRIPTION
The Set-AzResource cmdlet modifies an existing Azure resource. You can update properties of a resource that has already been deployed. To use this cmdlet, you need to specify the resource's name, its resource group, its resource type, and the API version to use for the update.
PARAMETERS
| Name | Type | Description | 
|---|---|---|
| -Name | [String] | Specifies the name of the resource to update. | 
| -ResourceGroupName | [String] | Specifies the name of the resource group that contains the resource. | 
| -ResourceType | [String] | Specifies the type of the resource. For example, "Microsoft.Storage/storageAccounts". | 
| -ApiVersion | [String] | Specifies the API version of the resource type to use. | 
| -InputObject | [PSObject] | Specifies an object that represents the resource to update. This object can be piped from other cmdlets. | 
| -Force | [Switch] | Suppresses prompts for confirmation. | 
| -AsJob | [Switch] | Runs the cmdlet as a background job. | 
| -WhatIf | [Switch] | Shows what would happen if the cmdlet runs. The cmdlet is not run. | 
| -Confirm | [Switch] | Prompts you for confirmation before running the cmdlet. | 
EXAMPLES
Example 1: Update a storage account's tags
This command updates the tags for a storage account named "myStorageAccount" in the "myResourceGroup".
Set-AzResource -ResourceGroupName "myResourceGroup" -ResourceType "Microsoft.Storage/storageAccounts" -Name "myStorageAccount" -ApiVersion "2021-09-01" -PropertyObject @{tags = @{"environment"="production"; "owner"="devteam"}}Example 2: Update a virtual machine's size using an input object
This command gets a virtual machine object, updates its size property, and then applies the change.
$vm = Get-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
$vm.HardwareProfile.VmSize = "Standard_D2s_v3"
Set-AzVM -VM $vm -ResourceGroupName "myResourceGroup"Note: While the example above uses `Set-AzVM` for clarity with VM objects, `Set-AzResource` can be used similarly for resources where direct property manipulation is possible through its parameters.
Example 3: Update a resource using a JSON patch
This example demonstrates how to use a JSON patch document to perform a partial update on a resource.
$patchBody = '{"properties":{"sku":{"name":"Standard_LRS"}}}'
Set-AzResource -ResourceGroupName "myResourceGroup" -ResourceType "Microsoft.Storage/storageAccounts" -Name "myStorageAccount" -ApiVersion "2021-09-01" -PropertyObject $patchBodyREMARKS
When you update a resource, you can either provide a complete resource object with all desired properties or a partial object containing only the properties you want to change. If you provide a partial object, only the specified properties will be updated. Other properties will remain unchanged.
It's recommended to use the -WhatIf parameter to simulate the changes before applying them. This helps prevent unintended modifications.