How to Find Unused Resources and Resources with Duplicate Names in Azure Using Code and Automatically Delete Them?

Jyoti Teli (BLR GSS) 60 Reputation points
2025-01-20T12:30:41.2266667+00:00

Hello,

I am trying to automate the process of identifying and deleting unused resources, as well as finding resources with duplicate names, in my Azure environment.

Specifically, I want to:

  1. Find unused resources in my Azure subscription (e.g., orphaned VMs, unattached disks, unused public IPs, etc.).
  2. Identify resources with duplicate names within the same resource group or subscription.
  3. Delete these resources automatically using a script or code.

I am looking for guidance on:

  • The best tools or services in Azure to query resources (e.g., Azure Resource Graph, Azure CLI, PowerShell, etc.).
  • Sample scripts or methods for detecting unused resources and duplicate names.
  • Best practices for safely deleting these resources to avoid any critical issues.

Any help, script examples, or advice would be greatly appreciated!

Thank you in advance! Hello,

I am trying to automate the process of identifying and deleting unused resources, as well as finding resources with duplicate names, in my Azure environment.

Specifically, I want to:

  1. Find unused resources in my Azure subscription (e.g., orphaned VMs, unattached disks, unused public IPs, etc.).
  2. Identify resources with duplicate names within the same resource group or subscription.
  3. Delete these resources automatically using a script or code.

I am looking for guidance on:

  • The best tools or services in Azure to query resources (e.g., Azure Resource Graph, Azure CLI, PowerShell, etc.).
  • Sample scripts or methods for detecting unused resources and duplicate names.
  • Best practices for safely deleting these resources to avoid any critical issues.

Any help, script examples, or advice would be greatly appreciated!

Thank you in advance!

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,300 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,792 questions
{count} votes

Accepted answer
  1. Marcin Policht 33,775 Reputation points MVP
    2025-01-20T13:37:23.8733333+00:00

    Follow https://www.geeksforgeeks.org/microsoft-azure-removing-unused-services-from-azure/


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.