SharePoint Online: Grant Site Owner Permission to a User with PowerShell

Requirement: Grant Site Owner Permissions to a User in SharePoint Online

How to Grant Site Owner Permissions to a User in SharePoint Online?

By adding people to the SharePoint Online site owners group, they can manage the site and perform typical site administration activities such as setting site branding and structure, adding or removing users, managing content, etc. To add a site owner to your SharePoint Online site, follow these steps:

  • Navigate to your SharePoint Online site, Click on Settings Gear >> and then click on the “Site Permissions” link
  • Click on the “Share Site” button on the Site Permissions pane.
    sharepoint online site owner powershell
  • Enter the user name in the search box and pick the user >> Select “Full Control” permission for the user and click on the “Add” button to grant the user site owner permissions.
    add site owner sharepoint online powershell

Alternatively, You can go to Site Settings >> Site Permissions >> Pick the relevant site owners group >> Click on “New” >> Add User to Group.

Add Site Owner in SharePoint Online using PowerShell

Here is how to add a user to the Owner group using PowerShell 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"
   
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/warehouse"
$UserAccount = "[email protected]"

#Setup Credentials to connect
$Cred = Get-Credential
  
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
      
    #Get the Default Owner Group of the site
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.Load($Web.AssociatedOwnerGroup)
    $Ctx.ExecuteQuery()
 
    #ensure the sharepoint online user
    $User=$web.EnsureUser($UserAccount)
  
    #sharepoint online powershell add user to owner group
    $Web.AssociatedOwnerGroup.Users.AddUser($User) | Out-null
    $Ctx.ExecuteQuery()
  
    write-host  -f Green "User '$UserAccount' has been added to Owners Group of the Site!"
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

SharePoint Online: PnP PowerShell to Add Site Owner

We can add site owner with PnP PowerShell cmdlet Add-PnPGroupMember as well:

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Warehouse"
$UserAccount= "[email protected]"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
 
#Get the Default Owners Group of the site
$OwnersGroup = Get-PnPGroup  -AssociatedOwnerGroup
 
#SharePoint Online pnp powershell to add site owner
Add-PnPGroupMember -LoginName $UserAccount -Identity $OwnersGroup

If you want to set a Primary Admin (Sometimes called “Site Owner”), here is another post: How to Add Primary Site Admin in SharePoint Online?

How do I make someone a collection administrator in SharePoint Online?

If you need to make someone else a site collection admin, You can do so with the SharePoint Admin center, the “Site Collection Administrators” settings page of the site, or using PowerShell.
More info: Change Site collection administrator in SharePoint Online

How to create a custom permission level in SharePoint Online?

You can copy any existing permission levels, such as “Contribute” and modify the new permission level by adding or removing permissions from it. E.g., You can create “Contribute without Delete” permission by removing “Delete” permissions from “Contribute”.
More info: Create custom permission in SharePoint Online

How do I give access to all authenticated users?

To share a SharePoint site with all internal users, grant access rights to the “Everyone except the external users” group.
More info: Grant permissions to all users in SharePoint Online

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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