@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 - 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.
- 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 .
- 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)
}
- Connect-AzureAD
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