Editar

Compartir a través de


Remove-AzVM

Removes a virtual machine from Azure.

Syntax

Remove-AzVM
      [-Name] <String>
      [-ForceDeletion <Boolean>]
      [-Force]
      [-NoWait]
      [-ResourceGroupName] <String>
      [-AsJob]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Remove-AzVM
      [-ForceDeletion <Boolean>]
      [-Force]
      [-NoWait]
      [-Id] <String>
      [-AsJob]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

The Remove-AzVM cmdlet removes a virtual machine from Azure.

Examples

Example 1: Remove a virtual machine

Remove-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"

This command removes the virtual machine named VirtualMachine07 in the resource group ResourceGroup11.

Example 2: Remove a VM in a VMSS with the orchestation mode set to Flex.

# Get a VMSS with the orchestation mode set to Flex.
$rgname = <Resource Group Name>
$vmssName = <VMSS Name>
$vmssFlex = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName 
$vmssvms = Get-AzVmssVM -ResourceGroupName $vmssFlex.ResourceGroupName -VMScaleSetName $vmssFlex.Name
# Get the first VM's name to delete it. 
$vmName = $vmssvms[0].Name
Remove-AzVM -ResourceGroupName $rgname -Name $vmName

This example shows how to delete a virtual machine within a virtual machine scale set of the orchestration mode Flex with this cmdlet. This will not work on a virtual machine scale set of orchestration mode Uniform.

Parameters

-AsJob

Run cmdlet in the background and return a Job to track progress.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Forces the command to run without asking for user confirmation.

Type:SwitchParameter
Position:2
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ForceDeletion

Optional parameter to force delete a VM.

Type:Nullable<T>[Boolean]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Id

The virtual machine resource Id.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

The resource name.

Type:String
Aliases:ResourceName, VMName
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-NoWait

Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has successfully been completed, use some other mechanism.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ResourceGroupName

Specifies the name of a resource group.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

Outputs

PSComputeLongRunningOperation

PSAzureOperationResponse