Hi @SKIFIN JOSEPH ,
Please try to use this:
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
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.