Here is a PowerShell script to remove invalid users from the SharePoint
Web Applications
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Get all the Site
Collections inside the Web Application
$SiteColl = Get-SPWebApplication "http://abc.xyz.com" | Get-SPSite -Limit All#Define the List of Users
$Users =@('domain\abc',’domain\xyz’)
#Iterate through
all the Site Collections
foreach($site in $SiteColl){
#Iterate through users to Remove
foreach($user in $Users)
{
#Check if User Exists in Site
if ($Site.RootWeb.SiteUsers | Where {$_.LoginName -eq $User})
{
$Site.RootWeb.SiteUsers.Remove($User)
Write-Host "$($user) has been Removed from the $($Site.RootWeb.URL)"
}
}
}