Add user as owner of all Office 365 groups using Powershell

As you know modern Office 365 groups are being used as base service for other Office 365 workloads (Ex: Teams, Planner).So you have to first member of the group to manage and work with groups and its associated services, if you want to do some high privilege actions (ex: delete group, delete team, or delete planner plan) then you have to be added as an owner of the group.

With Global Admin privilege, sometimes you may want to delete a group or update some group settings, but without being an owner of the group you can’t delete group even though you have global admin privilege. We can use Exchange Online Powershell cmdlet Add-UnifiedGroupLinks to add a user as owner and member of unified group.

Before proceed, first connect EXO Powershell module by using below commands :

$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session

The below commands add a user as owner and member of the specific group :

Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links [email protected]
Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Owners –Links [email protected]

Note: To get the complete privilege, you have to add the user as owner and also as a member of the group.

Add user as owner of all Office 365 Groups

To add a user as the owner of all the available o365 groups in your organization, first, you have to get all the unified groups using the Get-UnifiedGroup cmdlet and pipe the results to Add-UnifiedGroupLinks cmdlet to add user one by one.

$userToAddOwner = "[email protected]"
Get-UnifiedGroup -ResultSize Unlimited | ForEach-Object {
$o365group = $_
Add-UnifiedGroupLinks –Identity $o365group.Name –LinkType Members –Links $userToAddOwner
Add-UnifiedGroupLinks –Identity $o365group.Name –LinkType Owners –Links $userToAddOwner
}

Add user as owner of multiple groups from CSV

Consider the CSV file o365Groups.csv that includes the column GroupName which holds the name of groups in each row of the CSV file.

$userToAddOwner = "[email protected]"
Import-CSV "C:\o365Groups.csv" | ForEach-Object {
$groupName = $_."GroupName"
Add-UnifiedGroupLinks –Identity $groupName –LinkType Members –Links $userToAddOwner
Add-UnifiedGroupLinks –Identity $groupName –LinkType Owners –Links $userToAddOwner
}

You can use the Remove-UnifiedGroupLinks cmdlet to remove membership and ownership of a user from Office 365 group.


Advertisement

Leave a Comment