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, and Click on Settings Gear >> Click on the “Site Permissions” link.
- Click on the “Share Site” button on the Site Permissions pane.
- 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.
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
The Full Control permission allows the user to manage all aspects of the site, including adding and removing users, managing content, and managing settings. Here is how to add a user to the site 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 a site owner with the PnP PowerShell as well. To grant site owner permissions using PowerShell, first, connect to the SharePoint Online site using the Connect-PnPOnline cmdlet. Once connected, the user can use the Add-PnPGroupMember cmdlet to assign permissions to a user.
#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 up a Primary Admin (Sometimes called “Site Owner”), here is another post: How to Add Primary Site Admin 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
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
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