Bulk Delete Azure AD Groups from Azure AD With PowerShell

  • Post author:
  • Post category:Main
  • Post last modified:
  • Reading time:1 min read
  • Post published:

In this example, I am going to delete all Azure AD groups from my Azure AD tenant that have the word “test” in the name. This will be a fairly simple job to complete.

Full Script

 Get-AzureADGroup -SearchString "test" | Export-CSV C:\temp\groups.csv
 
 $groups = import-csv C:\temp\groups.csv
 
 foreach ($group in $groups) {
       $objectID = $group.objectID
       Remove-AzureADGroup -ObjectID $ObjectID
     }

Let’s break it down

Line 1  – Firstly we gather all Azure AD Groups with the string “test” in the name, then export this information to a CSV file in a temp for on C:\

Line 3 – We then import this CSV data into a variable called $groups so it can be manipulated in our PowerShell session. 

Line 5>8 – This last section will loop through each group in our $groups array, select the ObjectID of that group and parse that information into our remote-AzureADGroup command.

You can verify the command has worked with the following:

 Get-AzureADGroup -SearchString "test" 

Daniel Bradley

Daniel Bradley is a UK-based technical architect and Microsoft MVP in Security. He specialises in Microsoft Entra, Intune, and Microsoft Graph PowerShell and is the author of Microsoft Graph PowerShell for Administrators. He writes and edits Our Cloud Network using experience gained from working with Microsoft cloud environments.

Leave a Reply