SharePoint Online: Change User Permissions using PowerShell

Requirement:  Edit user permissions in SharePoint Online

How to change user permissions in SharePoint Online Site?

You want to change the user’s permission on a particular site/library/item in SharePoint online. E.g. Once a particular project has completed and you no longer want the team member to add or edit the project’s supporting documents but only view them! SharePoint provides a flexible way to manage permission changes to a user or a group. Here is how to update user permissions in SharePoint online.

  • To edit site permissions for a user, Navigate to the SharePoint Online site where the user has access. Click on the Settings gear and then site settings.
  • On the Site Settings page, click on the “Site Permissions” link under the Users and Permissions group.
  • On the site permissions page, select the checkbox next to the user which you want to edit permissions. Click on the “Edit User Permissions” button from the ribbon.
    edit user permissions sharepoint online
  • Select-Unselect the relevant permissions checkboxes. In this case, you have to untick “Edit” and tick “Read”. Click OK to save your changes.
    sharepoint online change user permissions
SharePoint online permissions will default to the highest level of security. E.g. If a user has both “Edit” and “Read” access, SharePoint considers “Edit”!

Please note, if the site or library is inheriting permissions from the parent, You may have to Stop Inheriting Permissions in order to provide unique permission to the item.

Edit user permissions in SharePoint Online using PowerShell:

Let’s script the above task of editing the user permissions. Remove “Edit” and add “Read” permission to the user at site level.

#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 = ""
$UserAccount="i:0#.f|membership|[email protected]"

#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 all Users of the site
    $Users = $Ctx.Web.SiteUsers
    #Get user accounts
    $UserAccounts =  $Users | Select -ExpandProperty LoginName

    #Check if the given user exists in the site
    If($UserAccounts -Contains $UserAccount)
        #Get the User
        $User = $ctx.Web.SiteUsers.GetByLoginName($UserAccount)

        #Get Permission Levels to add and remove
        $RoleDefToAdd = $Ctx.web.RoleDefinitions.GetByName($PermissionToAdd)
        $RoleDefToRemove = $Ctx.web.RoleDefinitions.GetByName($PermissionToRemove)
        #Get the User's role assignment on the web
        $RoleAssignment = $Ctx.web.RoleAssignments.GetByPrincipal($User)
        #Add/remove permission levels to the role assignment

        write-host  -f Green "User permissions updated Successfully!"
        Write-host -f Yellow "User Doesn't exist in the site!"
Catch {
    write-host -f Red "Error Updating User Permissions!" $_.Exception.Message

To add or remove permission level to a SharePoint Online Group using PowerShell, use: Change permission level of SharePoint group with PowerShell

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “SharePoint Online: Change User Permissions using PowerShell

Leave a Reply