Sometimes we need to delete a user from deleted users in Office 365 Admin Portal.

You can do most things using PowerShell, but that’s too much for such a simple task.

Step 1

First things first, we need to register an app in Azure. Go to Azure Active Directory > App Registrations and create a new app. Write down the (Application) Client ID and Directory (tenant) ID.

Go to API permissions and add the following “Application” permissions:

Application.ReadWrite.All
Directory.ReadWrite.All
Group.ReadWrite.All
User.ReadWrite.All

…then click Grant admin consent.

In Certificates & secrets click New client secret and create a new App Secret. Note it down now. Make sure you take note of the Value and not the Secret ID.

Step 2

Create a custom connector in Power Platform and call it Graph AD Directory. Go to Power Automate or Power Apps > Data > Custom Connectors. Give your connector a name and configure base URL as below:

Click next and under the authentication, select OAuth 2.0, select Azure Active Directory under identify provider.

Paste Client ID, Secret and Tenant ID from your notes. Use https://login.microsoftonline.com in Authorization URL and https://graph.microsoft.com/ in Resource URL and .default in scope.

Step 3

Create two definitions: ListDeletedItems and PermanentlyDeleteItem.

Create the first definition: Name it as ListDeletedItems and click Import from sample and paste this link: https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.group?$orderBy=displayName – the orderBy parameter is optional. Paste Accept application/json in headers, and click Import.

Create the second definition: Name it as PermanentlyDeleteItem and click Import from sample and paste this link: https://graph.microsoft.com/v1.0/directory/deletedItems/{object-id}. Paste Accept application/json in headers, and click Import.

Step 4

Create an app. Go to the Data tab, add a new connection, and search for the custom connector you created in Step 3.

Add a New Blank Screen. Create a button, rename it to btnListDeletedItems and paste the following into the OnSelect property:

ClearCollect(colDeletedItems,GraphADDirectory.ListDeletedItems({'$orderBy':"userPrincipalName"}).value)

Add a new Gallery control, and in Items, enter:

Sort(colDeletedItems,displayName,SortOrder.Ascending)

In the Screen OnVisible property, paste:

Select(btnListDeletedItems)

Inside the galley, you have a few properties to choose from, I selected: ThisItem.displayName, ThisItem.jobTitle and ThisItem.userPrincipalName. I also added a Trash icon and in the OnSelect property, paste the following:

GraphADDirectory.PermanentlyDeleteItem(ThisItem.id,{Accept:"application/json"});Select(btnListDeletedItems)

The first action is to delete the current object ID and the second action is to refresh the list of Deleted Items.

That’s it.