Remove-AzVM

Deletes a virtual machine.

Important: This action is irreversible. Ensure you have backups or understand the implications before proceeding.

SYNTAX

Remove-AzVM
    [-Name] 
    [-ResourceGroupName] 
    [-Force]
    [-AsJob]
    [-WhatIf]
    [-Confirm]
    []

DESCRIPTION

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.

PARAMETERS

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.

EXAMPLES

Example 1: Delete a virtual machine

This command deletes the virtual machine named "MyVM" in the resource group "MyResourceGroup".

Remove-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup"

Example 2: Delete a virtual machine without confirmation

This command deletes the virtual machine named "MyVM" in the resource group "MyResourceGroup" without prompting for confirmation.

Remove-AzVM -Name "MyVM" -ResourceGroupName "MyResourceGroup" -Force

Example 3: Delete a virtual machine and run as a background job

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

NOTES

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.

RELATED COMMANDS