Powershell script to clean the User Information List in SharePoint 2010
Requirement
Remove all users from a SharePoint site, including all entries in the User Information List which can be located at:
http://sitecollection/_catalogs/users/detail.aspx
Solution
#This script will delete all users in the User Information List. Change $url to your site/site collection.
$url = “http://sitecollection”
$web = get-spweb $url
$list = $web.Lists[“User Information List”]
$listItems = $list.Items
$listItemsTotal = $listItems.Count
for ($x=$listItemsTotal-1;$x -ge 0; $x–)
{
Write-Host(“DELETED: ” + $listItems[$x].name)
remove-spuser $listItems[$x][“Account”] -web $url -confirm:$false
}
$web.dispose()
Thanks Andrew,
You’re missing a ‘-‘ in line
for ($x=$listItemsTotal-1;$x -ge 0; $x–)
-> should be
for ($x=$listItemsTotal-1;$x -ge 0; $x-–)
Apart from that, great help, thanks – Dirk
Very good blog you have here but I was curious if you knew
of any community forums that cover the same topics talked about here?
I’d really love to be a part off community where I can get advice from other experienced people
that share the same interest. If you have any recommendations, please let me know.
Bless you!