Adding owners to 365 security groups

I needed to add an owner to multiple 365 security groups.  I had the security groups in a csv with a column for name.

You will need to connect-azuread prior to running the following:

$GroupName = import-csv groups.csv
$UserUPN = "anonit@anonit.net"
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
foreach ($object in $groupname)
{
  Add-AzureADGroupOwner -ObjectId (Get-AzureADGroup -SearchString $object.name).ObjectId -RefObjectId $AADUser.ObjectId
}

Leave a Reply

Your email address will not be published. Required fields are marked *