Remove-AzVM
Removes a virtual machine.
Syntax
Remove-AzVM
[-Name]
[-Force]
[-AsJob]
[-NoWait]
[-ResourceGroupName ]
[-SubscriptionId ]
[-DefaultProfile ]
[-WhatIf]
[-Confirm]
[]
Description
The Remove-AzVM cmdlet removes a virtual machine. This operation is irreversible.
Important
When you remove a virtual machine, the disk associated with the virtual machine is also removed by default. If you need to retain the disk, you must detach it before removing the VM or use the -Force parameter with caution.
Parameters
| Name | Type | Description |
|---|---|---|
-Name |
String | The name of the virtual machine. This parameter is mandatory. |
-Force |
Switch | Skips the confirmation prompt. Use this parameter to suppress the confirmation prompt. |
-AsJob |
Switch | Run cmdlet in the background. |
-NoWait |
Switch | Do not wait for the operation to complete. |
-ResourceGroupName |
String | The name of the resource group that contains the virtual machine. |
-SubscriptionId |
String | The ID of the subscription that contains the virtual machine. |
-DefaultProfile |
IAzureContextContainer | The credentials, account, tenant, and subscription for the cloud service. |
-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: Remove a virtual machine
This example removes a virtual machine named "MyVM" in the "MyResourceGroup" resource group.
Remove-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM"
Example 2: Remove a virtual machine without confirmation
This example removes the virtual machine "MyVM" without prompting for confirmation.
Remove-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM" -Force
Example 3: Remove a virtual machine as a background job
This example removes the virtual machine "MyVM" and runs the operation in the background.
Remove-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM" -AsJob