We have N number of groups and need to add bulk owners to the AAD groups by using PowerShell
We have N number of groups and need to add bulk owners to the AAD groups by using PowerShell
@NMBabu-1149 , When you say bulk owner ? Are you looking to add multiple group owner to a group ??
@NMBabu-1149 ,
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

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

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.

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 .

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
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
2 people are following this question.