Remove a User from SharePoint Group using PowerShell

How to Remove user from SharePoint group?

As a SharePoint administrator, you may need to remove users from groups from time to time. This can be done in the SharePoint site with the web browser interface or PowerShell. In this guide, we’ll walk you through the process of removing users from groups in SharePoint 2016 and 2013. We’ll also show you how to remove a user from a SharePoint group using PowerShell.

From the SharePoint Web interface, if you want to remove a user from the SharePoint group, log in as a SharePoint Administrator, navigate to:

  • Click on Site Settings Gear icon >> Click on Site Settings
  • From the Site settings page, click on the “People and Groups” link under the “Users and Permissions” group
    sharepoint powershell remove user from group
  • Select the group from the left navigation by click on the group from which you want to remove users.
    sharepoint 2013 remove user from group programmatically
  • Select the user(s) and click on Actions Menu >> Choose “Remove users from Group”
    remove user from sharepoint group using powershell

Confirm by clicking “OK”. Selected users are now removed from the SharePoint Group!

Delete a user from the SharePoint group using PowerShell: 

If you want to remove the user from a SharePoint group, this PowerShell script can help:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function RemoveUser-FromGroup($SiteURL, $GroupName, $UserAccount)
{
 try
    {
     $ErrorActionPreference = "Stop"
  
     #Get the Web
     $web=Get-SPWeb $SiteURL
    
     #Get the User to Remove 
     $User  = Get-SPUser -Identity $UserAccount -Web $web

     #Get the Group by its name
     $Group = $Web.sitegroups | Where-Object {$_.Name -eq $GroupName}
     if($Group -ne $null)
     {
         #sharepoint powershell delete user from group
         $Group.RemoveUser($User)
         Write-Host "$($User) Removed from the Group: $($GroupName)"
     }
   }
 catch
    { 
           #Write error message on screen and to a LOG file
           write-host $_.Exception.Message
    }
 finally
    {
           $ErrorActionPreference = "Continue"
    }
}

#Call the function to remove user from SharePoint group
RemoveUser-FromGroup "https://sharepoint.crescent.com/sites/Operations" "Operations Members" "Corp\DaveP"

This removes a given user from a specific SharePoint group. How about removing users from All groups on the site?

Remove user from all SharePoint groups

Let’s remove a user from All Groups in SharePoint using PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function RemoveUser-FromAllGroups($SiteURL, $UserAccount)
{
     #Get the Web
     $web=Get-SPWeb $SiteURL
    
     #Get the User to Remove 
     $User  = $Web.EnsureUser($UserAccount)

     #Iterate through all Groups
     foreach($Group in $Web.Groups)
     {
         $GroupUser = $Group.Users | where {$_.UserLogin -eq $User.UserLogin}
         #Check if user member of the group
         if($GroupUser -ne $null)
         {
            #remove user from sharepoint group using powershell 
            $Group.RemoveUser($User)
            Write-Host "$($User) Removed from the Group: $($Group)"
         }
     }
 }

 #Call the function to remove user from all groups in the site  
 RemoveUser-FromAllGroups "https://intranet.crescent.com" "Crescent\Salaudeen"

Web.Group vs. Web.SiteGroup: 
Web.SiteGroups gets you a collection of cross-site groups for the site collection. These groups can be used in more than one Web object in the site collection.

Web.Groups get you the groups with some permission on the specific Web (subsite). These groups may have permission somewhere on the site: E.g., List or List Item with broken permissions. So if you add the group to a site without any permission, then this group won’t appear on the Web.Groups collection, but it will appear on Web.SiteGroups collection.

Here is another article for SharePoint Online to Remove user from a group using PowerShell: SharePoint Online: Remove User from Group using PowerShell

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!

8 thoughts on “Remove a User from SharePoint Group using PowerShell

  • Hi
    I am trying to move SharePoint Groups from one site collection to another . In target site the sharepoint groups are got created. But the SP groups are showing in groups.aspx not in user.aspx
    Also when i click the group name in groups.aspx, it throws error that Group cannot be found. Also unable to create with the same group name .

    How to delete Sharepoint custom group using Memebershipgroup id.

    Reply
  • Hi All
    sorry but i’m new with powershell.
    In the script to remove a user from all groups i have to replace only “siteURL” and “UserAccount” correct?
    and…the script ends on row 23?

    thanks for the help

    Reply
  • I just have to say ‘Thank you’ to Salaudeen, for this site has helped me with several tough problems. I appreciate the support and sharing. Also, kudos to Edmond for the tip about the distinction between $Web.Groups and $Web.SiteGroups. Simple, but VERY handy!

    Reply
  • on the groups deleting a user from all groups

    this line: foreach($Group in $Web.Groups)

    used this instead to cater for all: foreach($Group in $Web.SiteGroups)

    This is on sharepoint 2016

    Reply
  • how about deleting multiple users from the sharepoint group

    Reply
    • Sure, You can either use the function “RemoveUser-FromAllGroups” repeatedly with different user accounts, to remove them from all groups or “RemoveUser-FromGroup” function with specific group names.

      Reply

Leave a Reply

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