Delete Users from User information List.
Get the user details from previous script matching the criteria and use excel to import from text and get the CSV
#This script will remove users specified in the CSV.
$CSVFile = Import-CSV D:\Indra\Users.CSV # Change the path
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
#Get all site collections
$Sites = Get-SPSite -Limit All
$AllSites = @()
foreach($Line in $CSVFile)
{
foreach($Site in $Sites)
{
#Get the rootweb for the site collection
$RootWeb = $Site.RootWeb
If([bool](Get-SPUser $Line.Username -Web $RootWeb -EA SilentlyContinue) -eq $True)
{
#Remove the user from the User Information List
Remove-SPUser -Identity $Line.username -Web $RootWeb -Confirm:$False
$AllSites += $RootWeb.Url
}
}
if(!($AllSites).count -eq 0)
{
#Give feedback on deleted users
Write-Host "Removed user $($Line.username) from:" -Fore "Magenta"
foreach($S in $AllSites){Write-Host "- $S"}
Write-Host ""
$AllSites = @()
}
}