0%

Delete Useless AAD App

Delete Useless AAD App With PowerShell Script

A powershell script used to delete useless AAD app under your account.

Prerequsite

Usage

  1. Create a deleteAADAapp.ps1 file.

    1
    2
    3
    4
    5
    6
    7
    8
    az ad app list --filter "startswith(displayName, 'dilin')" --query '[].appId' > rawAppIds.log

    (Get-Content rawAppIds.log | Where-Object { $_ -ne '[' -and $_ -ne ']' -and $_ }) -split '\n' | ForEach-Object -Process {
    $id = $_.Trim() -replace ',','' -replace "``n","";
    $deleteAppCommand = 'az ad app delete --id ' + $id;
    Write-Output "Executing delete command: $deleteAppCommand";
    Invoke-Expression $deleteAppCommand
    }
  2. Change the filter expression in deleteAADAapp.ps1 to suit your need. [REF: OData filter / az ad app list]

  3. In powershell terminal, execute the below command:

    1
    2
    3
    4
    5
    # login account you would like to delete useless AAD app
    az logout && az login
    az account show

    .\deleteAADAapp.ps1

Reference GitHub Repo

delete-useless-aad-app-by-name-tool