Wednesday, May 1, 2013

SharePoint People Picker Showing Deleted Users? Remove with PowerShell

Problem:
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

Solution:
We've to remove the users from 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 User Information List to fix this problem.

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

This time, Lets 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 =@('ME\JamieT', 'Corp\EinstinS', 'Global\MarcM')

#Get all Site Collections
$SiteColl = Get-SPWebApplication "http://sharepoint.crescent.com" | 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)"
   }
  }
 
}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...