SharePoint People Picker Showing Deleted Users? Remove with PowerShell

Few consultants left the company after their contract is over. Their AD account was deleted, They are removed from SharePoint site collections even. But still, SharePoint People picker showing deleted users!

Root cause:
Because, People picker gets users NOT only from AD, But from "User Information List" of the site collection also, which is explained in one of my post: SharePoint People Picker Showing Deleted User Accounts from Active Directory and SharePoint Site

We've to remove the users from the hidden User Information list. For a quick fix, we can navigate to: http://your-sharepoint-site/_layouts/people.aspx?MembershipGroupID=0 and remove users from the User Information List to fix this problem.

But how about removing multiple users in bulk from all site collections? Well, I wrote a utility to remove users from the User Information List in C# SharePoint Object Model  Delete Users and Clean up User Information List

This time, let's do it with PowerShell.

PowerShell Script to fix SharePoint People Picker Showing Deleted Users:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Define the Array with List of Users
$Users [email protected]('ME\JamieT', 'Corp\EinstinS', 'Global\MarcM')

#Get all Site Collections
$SiteColl = Get-SPWebApplication "" | Get-SPSite -Limit All

#Iterate through all Site Collections
foreach($site in $SiteColl)
 #Iterate through the 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)  #You can also use: Remove-SPUser cmdlet
   Write-Host "$($user) has been Removed from $($Site.RootWeb.URL)"


Please Login and comment to get your questions answered!

Powered by Blogger.