Remove-AzResource

Removes a resource.

SYNTAX

Remove-AzResource [-Name] <String> [-ResourceType] <String> [-ApiVersion] <String> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]

Remove-AzResource -ResourceId <String> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]

Remove-AzResource -InputObject <PSObject> [-Force] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

The Remove-AzResource cmdlet removes a resource from Azure.

This cmdlet is a low-level cmdlet that works directly with Azure Resource Manager (ARM). For specific resource types, use the cmdlets provided by the relevant Azure PowerShell module. For example, to remove a virtual machine, use Remove-AzVM.

PARAMETERS

Name Type Description
-Name [String] Specifies the name of the resource to remove.
-ResourceType [String] Specifies the resource type of the resource to remove. For example, Microsoft.Storage/storageAccounts or Microsoft.Compute/virtualMachines.
-ApiVersion [String] Specifies the API version to use for the resource type. For example, 2020-01-01.
-ResourceId [String] Specifies the resource ID of the resource to remove. The resource ID is a string that uniquely identifies the resource in Azure.
-InputObject [PSObject] Specifies an object that represents the resource to remove. You can pipe a resource object to this cmdlet.
-Force [Switch] Forces the command to run without asking for confirmation.
-AsJob [Switch] Run cmdlet in the background using Azure PowerShell Job.
-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.

RELATED LINKS

EXAMPLES

Example 1: Remove a resource by name and type

Remove-AzResource -Name "myResource" -ResourceType "Microsoft.Web/sites" -ApiVersion "2021-02-01"

This command removes a web app named "myResource" using the API version 2021-02-01.

Example 2: Remove a resource by resource ID

Remove-AzResource -ResourceId "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount"

This command removes a storage account using its full resource ID.

Example 3: Remove a resource using piped input

Get-AzResource -Name "myVM" -ResourceType "Microsoft.Compute/virtualMachines" | Remove-AzResource

This command first gets a virtual machine and then pipes it to Remove-AzResource to delete it.

Example 4: Remove a resource without confirmation

Remove-AzResource -ResourceId "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Network/virtualNetworks/myVnet" -Force

This command removes a virtual network without prompting for confirmation.