You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/resize-vm.md
+31-17Lines changed: 31 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,31 +124,45 @@ az vm resize \
124
124
125
125
**Use PowerShell to resize a VM not in an availability set.**
126
126
127
-
This script sets the variables `$resourceGroup`, `$vm`, and `$size`. It then checks if the desired VM size is available by using `az vm list-vm-resize-options` and checking if the output contains the desired size. If the desired size isn't available, the script exits with an error message. If the desired size is available, the script deallocates the VM, resizes it, and starts it again.
127
+
This Cloud shell PowerShell script initializes the variables `$resourceGroup`, `$vm`, and `$size` with the resource group name, VM name, and desired VM size respectively. It then retrieves the VM object from Azure using the `Get-AzVM` cmdlet. The script modifies the `VmSize` property of the VM's hardware profile to the desired size. Finally, it applies these changes to the VM in Azure using the `Update-AzVM` cmdlet.
128
128
129
129
```azurepowershell-interactive
130
130
# Set variables
131
-
$resourceGroup = "myResourceGroup"
132
-
$vm = "myVM"
133
-
$size = "Standard_DS3_v2"
134
-
135
-
# Check if the desired VM size is available
136
-
if ((az vm list-vm-resize-options --resource-group $resourceGroup --name $vm --query "[].name" | ConvertFrom-Json) -notcontains $size) {
137
-
Write-Host "The desired VM size is not available."
As an alternative to running the script in Azure Cloud Shell, you can also execute it locally on your machine. This local version of the PowerShell script includes additional steps to import the Azure module and authenticate your Azure account.
140
142
141
-
# Deallocate the VM
142
-
az vm deallocate --resource-group $resourceGroup --name $vm
143
+
> [!NOTE]
144
+
> The local PowerShell may require the VM to restart to take effect.
143
145
144
-
# Resize the VM
145
-
az vm resize --resource-group $resourceGroup --name $vm --size $size
146
146
147
-
# Start the VM
148
-
az vm start --resource-group $resourceGroup --name $vm
0 commit comments