How to Bulk Import CSV to add owner to Groups Using Powershell in Azure AD

Kasumu, Abimbola 26 Reputation points
2023-01-05T16:56:11.477+00:00

I am Looking for a Script where i can add owner to 100 Security Groups by Bulk Import Power shell cmdlet

Please help !!!

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.5K Reputation points MVP Volunteer Moderator
    2023-01-05T18:36:49.23+00:00

    Hi @Kasumu, Abimbola ,

    maybe this helps to get started

    CSV-File (AzureADgroups.csv)

    GroupName,GroupOwner  
    groupPeter,******@yourdomain.net   
    groupPaul,******@yourdomain.net  
    

    PowerShell Script (installed AzureAd PowerShell module required):

    Import-Module AzureAD  
    Connect-AzureAD  
    Import-Csv -Path "Junk\AzureADgroups.csv" | ForEach-Object {  
      $ownerUserObj = Get-AzureADUser -ObjectId ($_.GroupOwner).Trim()  
      $AADgroupObj = Get-AzureADGroup -SearchString ($_.GroupName).Trim()  
      Add-AzureADGroupOwner -ObjectId $($AADgroupObj.ObjectId) -RefObjectId $($OwnerUserObj.ObjectId)  
    }  
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Kasumu, Abimbola 26 Reputation points
    2023-01-05T19:06:21.367+00:00

    Thank you!

    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.