How to Add Owner to Office 365 Group using PowerShell?

Requirement: Add Owner to Office 365 group using PowerShell

How to Set Group Owners in Office 365?
To add members to Office 365 group through Microsoft 365 admin center, follow these steps:
  • Login to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  • Expand Groups and Click on Groups link in the left navigation. 
  • Search and Select the Office 365 group you wish to add owner.
  • In the Group details page, Click on "Members" tab >> Click on View all and manage Owners link. 
  • Click on "Add Owners" button on the top of the page >> Search and select users you wish to add to the group >> Hit "Save" button once done!
    add owner to office 365 group powershell

Add Owner to Office 365 Group using PowerShell
To add a user as an owner of an Office 365 group, we need to add them as a "member" to the group first and then we have to add the user as owner.
#Get Credentials to connect
$Credential = Get-Credential
  
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
  
#Import the session
Import-PSSession $Session -DisableNameChecking | Out-Null

#PowerShell to add Owner to office 365 group
Add-UnifiedGroupLinks –Identity "[email protected]" –LinkType "Members" –Links "[email protected]"
Add-UnifiedGroupLinks –Identity "[email protected]" –LinkType "Owners" –Links "[email protected]"

#Remove the session
Remove-PSSession $Session
Similarly, to add Owner to All Office 365 groups, use:
#Parameter
$GroupOwner = "[email protected]"

#Get Credentials to connect
$Credential = Get-Credential
  
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
  
#Import the session
Import-PSSession $Session -DisableNameChecking | Out-Null

#Get All Office 365 Groups and Add Group Owner
Get-UnifiedGroup -ResultSize Unlimited | ForEach-Object {
    Add-UnifiedGroupLinks –Identity $_.Name –LinkType Members –Links $GroupOwner
    Add-UnifiedGroupLinks –Identity $_.Name –LinkType Owners –Links $GroupOwner
    Write-host "Added Owner to Group:"$_.DisplayName
}

#Remove the session
Remove-PSSession $Session

Office 365: Change Group Owner using PowerShell
We can also set group owners with Azure AD cmdlets as well.
#Parameters
$GroupName = "Purchase"
$UserUPN = "[email protected]"

#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null

#Get the Azure AD User
$AADUser  = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"

#Add Group Owner
Add-AzureADGroupOwner -ObjectId (Get-AzureADGroup -SearchString $GroupName).ObjectId -RefObjectId $AADUser.ObjectId

To add members to Office 365 group, use: How to Add Members to Office 365 Group using PowerShell?

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.