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

Microsoft 365 and Office SharePoint Server For business
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CaseyYang-MSFT 10,461 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.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.