Bulk Delete Azure AD Groups from Azure AD With PowerShell

  • Post author:
  • Post category:Main
  • Post last modified:November 10, 2022
  • Reading time:1 mins read

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

My name is Daniel Bradley and I work with Microsoft 365 and Azure as an Engineer and Consultant. I enjoy writing technical content for you and engaging with the community. All opinions are my own.

Leave a Reply