Assign bulk owners to bulk Azure Active Directory groups" in a single go by using powershell

NM Babu 1 Reputation point
2022-03-31T06:40:29.073+00:00

We have N number of groups and need to add bulk owners to the AAD groups by using PowerShell

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,424 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shashi Shailaj 7,606 Reputation points Microsoft Employee
    2022-04-01T15:37:06.933+00:00

    @NM Babu ,
    If I understand correctly you would like to create a script which adds multiple owners to multiple groups by running a single powershell script . This can be done in multiple ways however I would use the simplest one. You would need to create a csv file with all the details for the owners that you want to add.

    • Export the list of groups in your organization with Object Ids and Display names. The output should look like in the screenshot. Connect-AzureAD
      Get-AzureADGroup | Select-Object ObjectID, DisplayName | Export-Csv c:\temp\group.csv
      • 189198-image.png
    • Export a list of users in your organization which you would like to add as owners with their Object Ids and Display Names . The output should be as in the screenshot.
        Connect-AzureAD         
      Get-AzureADUser | Select-Object ObjectId, DisplayName | Export-Csv C:\temp\users.csv    
      
      • 189168-image.png
    • Create a new csv file with the list of groups and the list of users to be added as owners. This is a manual step and will take time.
    • If you require to set multiple owners of the same group , you need to add the same group in the line.
    • Also if you see the details , I have modified the column titles to gObjectId (group objectid) gDisplayName (group displayname) UserOId (user objectid) UserDisplayName (user name) as per the usage in the script .
      • 189219-image.png Connect-AzureAD
        $Groups = Import-Csv "C:\Temp\groupOwner.csv"| ForEach-Object {
        Add-AzureADGroupOwner -ObjectId $($.gObjectId) -RefObjectId $($.userOid)
        Write-Host "$($.UserDisplayName) was added as a owner of the group $($.gDisplayName)"
        Get-AzureADGroupOwner -ObjectId $($_.gObjectId)
        }

    The output is received as below for the above script .

    189281-image.png

    Hope the above fits your requirement . Should you have any further query , do let us know. There could surely be other ways to do the same thing . But this will work for bulk group to bulk owner assignment . In any case you would have build a csv file beforehand in order to do it onetime. If the information in the post is helpful , do accept the post as answer which will help other members of the community searching for similar queries . We will be happy to help for any other query .


    • Please don't forget to click on 130616-image.png whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.