I'm trying to delete a lot of apps that carry a similar property with AZ AD CLI.
I can't find any good examples on --filter
Attempting to do something like this:
ad az app list --filter (displayName like 'stack') | ad az app delete
Any pointers greatly appreciated.
You can use --filter
like this
az ad app list --filter "startswith(displayName,'MyCommonPattern')"
Above mentioned command may give you quite a bit of json in output.
You can boil it down to just the appIds or whatever you need using --query
like this
az ad app list --filter "startswith(displayName,'RohitCommonPattern')" --query '[].appId'
Sample output
[
"b5exxxc4-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"f13xxxa5-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
]
I have shown this example using startswith
but you could use other operators as well like eq
, any
for collections, logical operators like and
, or
. Do look at the link related to Azure AD Graph API for more samples.
One more thing that I did try but isn't probably supported is contains
More information
--filter
accepts OData filter as per Microsoft Docs - az ad app list
Here is a general specification, although not everything may be implemented behind the scenes.
NOTE: I have intentionally mentioned older Azure AD Graph API https://graph.windows.net
and not the newer Microsoft Graph API https://graph.microsoft.com
since Application related APIs are still in beta for Microsoft Graph API.
To follow this up from Rohit's literally perfect answer, I added a quick BASH script to accomplish my loop:
for fn in `az ad app list --filter "startswith(displayName, 'Azure Stack')" --query '[].appId'`; do az ad app delete --id $fn; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With