Delete Useless AAD App With PowerShell Script
A powershell script used to delete useless AAD app under your account.
Prerequsite
- Azure-cli
- Platform: Windows
Usage
Create a
deleteAADAapp.ps1
file.1
2
3
4
5
6
7
8az 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
}Change the filter expression in
deleteAADAapp.ps1
to suit your need. [REF: OData filter / az ad app list]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