Azure Cloud Shell | remove app registration

251 views Asked by At

I'm trying to build a cleanup script that removes azure app registration from the cloud account.

From Azure documentation, I built a delete command but received an error.

I have the permission to remove the app registration manually, but the command failed.

The command that I ran:

Remove-AzureADApplication -ObjectId "$appRegistryObjectId"

The error that I received:

Remove-AzureADApplication: Error occurred while executing RemoveApplication 
Code: Request_BadRequest
Message: Value cannot be null.
Parameter name: requestContext
RequestId: 948d5c0c-e012-4ae8-b042-e6ae84ad4512
DateTimeStamp: Sun, 15 Oct 2023 12:31:29 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed

Can someone assist?

1

There are 1 answers

11
Imran On BEST ANSWER

I have one Application in my environment like below:

![enter image description here](https://i.imgur.com/scLXyiW.png)

To remove Remove-AzureADApplication ensure that you are passing correct objectID values:

$appRegistryObjectId = "2ea9b6aa-745b-41e5XXXXX"
Remove-AzureADApplication -ObjectId $appRegistryObjectId

![enter image description here](https://i.imgur.com/ZDOFwhW.png)

enter image description here

In portal App removed successfully like below:

enter image description here

Reference:

Remove-AzureADApplication (AzureAD) | Microsoft Learn

This error occurring if your account type is in AzureADandPersonalMicrosoftAccount

enter image description here

Make sure to change "signInAudience": "AzureADMultipleOrgs", like below:

enter image description here

Now, when I ran the same code App removed successfully.

Update

To can change signInAudience: "AzureADMultipleOrgs", and remove application using below command:

# Define variables
$appDisplayName = "imranapp1"
$appSigninAudience = "AzureADMultipleOrgs"
$appRegistryObjectId = "7d1655f1-9dbf-41fb-9906-xxxxx"

# Create an Azure AD application
az ad app create --display-name "$appDisplayName" --sign-in-audience "$appSigninAudience"

# Remove the Azure AD application
Remove-AzureADApplication -ObjectId "$appRegistryObjectId"

enter image description here

Now App registration change to AzureADMultipleOrgs and removed Application successfully like below:

enter image description here