Azure PowerShell Documentation

Remove-AzResource

Deletes an Azure resource.

SYNTAX

Remove-AzResource
    -Name -s string
    -ResourceType -s string
    -ResourceGroupName -s string
    [-Force]
    [-AsJob]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

DESCRIPTION

The Remove-AzResource cmdlet deletes a resource in Azure Resource Manager. You can delete a resource by specifying its name, resource type, and resource group.

PARAMETERS

Name Type Description
-Name System.String The name of the resource to delete.
-ResourceType System.String The type of the resource. For example, 'Microsoft.Storage/storageAccounts' or 'Microsoft.Compute/virtualMachines'.
-ResourceGroupName System.String The name of the resource group that contains the resource.
-Force System.Management.Automation.SwitchParameter Suppresses the confirmation prompt. By default, the cmdlet prompts for confirmation before deleting the resource.
-AsJob System.Management.Automation.SwitchParameter Run cmdlet in the background.
-WhatIf System.Management.Automation.SwitchParameter Shows what would happen if the cmdlet runs. The cmdlet is not run.
-Confirm System.Management.Automation.SwitchParameter Prompts you for confirmation before running the cmdlet.
System.Object This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, OutVariable. For more information, type: Get-Help about_CommonParameters.

EXAMPLES

Example 1: Delete a storage account

This command deletes a storage account named "myStorageAccount" in the resource group "myResourceGroup".

# Delete a storage account
Remove-AzResource -Name "myStorageAccount" -ResourceType "Microsoft.Storage/storageAccounts" -ResourceGroupName "myResourceGroup"

Example 2: Delete a virtual machine without confirmation

This command deletes a virtual machine named "myVM" in the resource group "myVMResourceGroup" without prompting for confirmation.

# Delete a virtual machine without confirmation
Remove-AzResource -Name "myVM" -ResourceType "Microsoft.Compute/virtualMachines" -ResourceGroupName "myVMResourceGroup" -Force

Example 3: Use -WhatIf to see what would happen

This command shows what would happen if you tried to delete a resource, without actually deleting it.

# Preview deletion of a resource
Remove-AzResource -Name "myResourceToDelete" -ResourceType "Microsoft.Web/sites" -ResourceGroupName "myWebApps" -WhatIf

Note

When deleting resources, it's a good practice to use the -WhatIf parameter first to verify the intended action before executing the actual deletion.