Update-AzVM
This cmdlet is part of the Az.Compute module. To use it, you need to install the module first.
You can install it using: Install-Module -Name Az.Compute.
SYNOPSIS
Updates a virtual machine.
SYNTAX
Update-AzVM
[-VM] <PSVirtualMachine>
[-SubscriptionId <String>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
DESCRIPTION
The Update-AzVM cmdlet updates a virtual machine. You can use this cmdlet to modify various properties of a virtual machine, such as its size, configuration, or settings.
PARAMETERS
| Name | Type | Description | Required? |
|---|---|---|---|
| VM | Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine | The virtual machine object to update. This object can be retrieved using the Get-AzVM cmdlet. |
Yes |
| SubscriptionId | System.String | The subscription ID to use for the operation. If not specified, the current context's subscription is used. | No |
| DefaultProfile | Microsoft.Azure.Commands.Common.Authentication.IAzureContextContainer | The Azure context to use for the operation. | No |
| WhatIf | System.Management.Automation.SwitchParameter | Performs the cmdlet in the form of a simulation. The cmdlet does not run the operation, but it displays what would happen if the operation were run. | No |
| Confirm | System.Management.Automation.SwitchParameter | Prompts you for confirmation before running the cmdlet. | No |
EXAMPLES
Example 1: Resize a virtual machine
# Get the virtual machine
$vm = Get-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup"
# Update the VM size
$vm.HardwareProfile.VmSize = "Standard_D2s_v3"
# Update the virtual machine
Update-AzVM -VM $vm
Example 2: Change the OS disk type
# Get the virtual machine
$vm = Get-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup"
# Change the OS disk type to Premium SSD
$vm.StorageProfile.OsDisk.StorageAccountType = "Premium_LRS"
# Update the virtual machine
Update-AzVM -VM $vm