Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Remove-AzVM
- Module:
- Az.Compute Module
Removes a virtual machine from Azure.
Syntax
ResourceGroupNameParameterSetName (Default)
Remove-AzVM
[-Name] <String>
[-ResourceGroupName] <String>
[-ForceDeletion <Boolean>]
[-Force]
[-NoWait]
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
IdParameterSetName
Remove-AzVM
[-Id] <String>
[-ForceDeletion <Boolean>]
[-Force]
[-NoWait]
[-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 orchestration mode set to Flex.
# Get a VMSS with the orchestration 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.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
-Force
Forces the command to run without asking for user confirmation.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ForceDeletion
Optional parameter to force delete a VM.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Id
The virtual machine resource Id.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Name
The resource name.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | ResourceName, VMName |
Parameter sets
-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.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ResourceGroupName
Specifies the name of a resource group.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
String
Outputs
PSComputeLongRunningOperation
PSAzureOperationResponse
Related Links
Azure PowerShell
Feedback
Was this page helpful?
