Deletes a virtual machine.
Remove-AzVM
[-Name]
[-ResourceGroupName]
[-Force]
[-AsJob]
[-WhatIf]
[-Confirm]
[]
The Remove-AzVM cmdlet deletes a virtual machine. You can use this cmdlet to delete a virtual machine that is in the Stopped or Deallocated state.
| Parameter | Type | Description |
|---|---|---|
-Name |
System.String |
Specifies the name of the virtual machine to delete. |
-ResourceGroupName |
System.String |
Specifies the name of the resource group to which the virtual machine belongs. |
-Force |
SwitchParameter |
Do not ask for confirmation. By default, the cmdlet asks for confirmation before deleting the virtual machine. |
-AsJob |
SwitchParameter |
Run cmdlet in the background. |
-WhatIf |
SwitchParameter |
Shows what would happen if the cmdlet runs. The cmdlet is not run. |
-Confirm |
SwitchParameter |
Prompts you for confirmation before running the cmdlet. |
This command deletes the virtual machine named "MyVM" in the resource group "MyResourceGroup".
Remove-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup"
This command deletes the virtual machine named "MyVM" in the resource group "MyResourceGroup" without prompting for confirmation.
Remove-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup" -Force
This command deletes the virtual machine named "MyVM" in the resource group "MyResourceGroup" and runs the operation as a background job.
Remove-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup" -AsJob
To delete a virtual machine, the virtual machine must be in a stopped state and deallocated. If the virtual machine is running, you must stop and deallocate it first using the Stop-AzVM cmdlet with the -Force parameter.