kwizcom banner advertisement

SharePoint Online: Change Group Owner using PowerShell

SharePoint groups simplifies permission administration by assigning a set of users to a group and assigning permissions to them through the group. When we create a site, The default Owner Group of the site is assigned as Group owner for all groups. If anyone create a custom group, then they'll be assigned as group owner.

How to Change the Group Owner in SharePoint Online?
Follow these steps to change the owner of a group in SharePoint Online.
  • Go to Site Settings >>  People and Groups
  • Pick the group you want change the group owner from the left navigation
  • From the group page, Click on Settings >> Group Settings 
  • Enter the new group owner in "Group Owner" field. Hit OK to save your changes. This changes owner of a SharePoint Online group.
sharepoint online change group owner powershell

PowerShell to Change Group Owner in SharePoint Online: 
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL= "https://abraaj.sharepoint.com"
$GroupName="Team Site Members"
$GroupOwnerName="Salaudeen@abraaj.com"
#$GroupOwnerName="Team Site Owners"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the Group owner - Can be an another Group or User Account
    #$GroupOwner = $Ctx.Web.SiteGroups.GetByName($GroupOwnerName)
    $GroupOwner = $Ctx.Web.EnsureUser($GroupOwnerName)
    
    #Get the Group
    $Group = $Ctx.Web.SiteGroups.GetByName($GroupName)

    #Set the Group Owner
    $Group.Owner = $GroupOwner
    $Group.Update()
    $Ctx.ExecuteQuery()

    Write-host -f Green "Group Owner has been Updated!"
}
Catch {
    write-host -f Red "Error changing Group Owner!" $_.Exception.Message
}

Set Group Owner using SharePoint Online Management Shell:
Other than CSOM, You can also use SharePoint Online Management Shell to set the owner of a SharePoint Online group.
#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com"
$GroupName="Team Site Members"
$OwnerName="Salaudeen@crescent.com"
 
#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
 
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –credential $Cred

#Set the Group Owner
Set-SPOSiteGroup -Site $SiteURL -Identity $GroupName -Owner $OwnerName

PowerShell to Change Group Owner for All Groups in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$GroupOwnerName="Team Site Owners"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the Group owner - Can be an another Group or User Account
    $GroupOwner = $Ctx.Web.SiteGroups.GetByName($GroupOwnerName)
    
    #Get All Groups of the Site
    $GroupsColl = $Ctx.web.SiteGroups
    $Ctx.Load($GroupsColl)
    $Ctx.ExecuteQuery()

    #Iterate through each Group - Exclude SharePoint Online System Groups!
    ForEach($Group in $GroupsColl | Where {$_.OwnerTitle -ne "System Account"})
    {
        Write-Host -f Yellow "Changing the Owner of the Group:", $Group.Title

        #Set the Group Owner
        $Group.Owner = $GroupOwner
        $Group.Update()
        $Ctx.ExecuteQuery()
    }    

    Write-host -f Green "All Group Owners are Updated!"
}
Catch {
    write-host -f Red "Error changing Group Owners!" $_.Exception.Message
}
Here is my another post written for SharePoint On-premises: How to Change the Group Owner in SharePoint using PowerShell
SharePoint Online: Change Group Owner using PowerShell SharePoint Online: Change Group Owner using PowerShell Reviewed by Salaudeen Rajack on May 29, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.