Monday, June 15, 2015

Script to clear User Information List


while restoring site back ups, all users from orgin server would be there in destination server which requires some effort for removing. A simple SharePoint PowerShell script to clear the user information list, which in turn removes all users from all groups but not from lists
 $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()

No comments:

Post a Comment