Remove-AzVM

This cmdlet deletes a virtual machine (VM).

SYNOPSIS

Deletes a virtual machine.

SYNTAX

Remove-AzVM
    [-Name] <String>
    [-ResourceGroupName] <String>
    [-Force]
    [-AsJob]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

DESCRIPTION

The Remove-AzVM cmdlet deletes a virtual machine (VM). You can delete a VM by specifying its name and the resource group name.

This operation is asynchronous and returns immediately. The VM will be deleted in the background.

PARAMETERS

Name Type Description
-Name String Specifies the name of the virtual machine to delete.
-ResourceGroupName String Specifies the name of the resource group that contains the virtual machine.
-Force Switch Forces the command to run without asking for user confirmation.
-AsJob Switch Runs the cmdlet as a background job. Use this parameter to run the cmdlet while receiving and processing other messages from the Windows PowerShell session.
-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.
<CommonParameters> Object This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

EXAMPLES

Example 1: Delete a virtual machine

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

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

Example 2: Delete a virtual machine without confirmation

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

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

Example 3: Delete a virtual machine using pipeline

This command gets the virtual machine object named "MyVM" from the resource group "MyResourceGroup" and pipes it to Remove-AzVM.

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