Removing user from content database and entire SharePoint 2016 Farm

Srabon 21 Reputation points
2021-12-27T15:09:18.407+00:00

Hi,
Is there any script which will help us to completely remove an user from entire SharePoint Farm and Content Database as if the user will become a brand new user to SharePoint site?

In which table of the content database does the user information belong to?

Thanks

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,818 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,321 Reputation points
    2021-12-28T03:26:48.307+00:00

    Hi @Srabon ,

    You could try to use the following PowerShell script to remove user.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
       
    Function Delete-UserFromAllSites([string]$WebAppURL, [string]$UserID)  
    {  
        #Get All Site collections  
        $SitesColl = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All  
       
        foreach($Site in $SitesColl)  
        {  
            write-host "Processing site:" $Site.RootWeb.URL  
               
            #Check if user Exists in the site collection  
            $User = $Site.RootWeb.SiteUsers | Where-Object {$_.LoginName -eq $UserID}  
                  
            #If user account found  
            if($User -ne $null)  
            {  
                #Remove User from the Site  
                Remove-SPUser $UserID -web $Site.RootWeb.URL -confirm:$false  
                write-host "Removed user from site collection:"$Site.RootWeb.URL -f Green  
            }         
        }     
    }  
       
    #Variables for processing  
    $WebAppURL = "https://Portal.Crescent.com/"  
    $UserID="Crescent\DaveP"  
       
    #Call the function  
    Delete-UserFromAllSites $WebAppURL $UserID  
    

    And the UserInfo Table stores descriptive properties and security information about principals with access to a site collection.

    160775-1.png

    For Reference:
    UserInfo Table
    Remove User from All Sites in SharePoint using PowerShell
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.