0

I need to delete all the Users from the hidden List _catalog/users where user's domain is NorthP so sample user would be NorthP\johnd. What am I missing from the following PS code?

ADD-PSSNAPIN MICROSOFT.SHAREPOINT.POWERSHELL -EA CONTINUE
$SITE = GET-SPSITE "HTTP://siteurl/site"
$WEB = $SITE.ROOTWEB
$LIST = $WEB.LISTS["USER INFORMATION LIST"]

$I = $LIST.ITEMS | WHERE {$_["ACCOUNT"] -Like '*NorthP\*'}
$I.DELETE()
$WEB.DISPOSE()
$SITE.DISPOSE()
2
0

Try below code

add-pssnapin microsoft.sharepoint.powershell -ea continue
$site = get-spsite "http://siteurl/site"
$web = $site.rootweb
$list = $web.lists["user information list"]

$items = $list.items | where-object {$_["Account"] -like '*northp*'}

$listItemsTotal = $items.Count;
for($x=$listItemsTotal-1;$x -ge 0; $x--)
{
    $item = $list.GetItemById($items[$x].Id)
    remove-spuser $items[$x]["Account"] -web $web -confirm:$False
}

$web.dispose()
$site.dispose()
8
  • there is something wrong with this where {$_["account"] -like '*northp*' because the count is zero. but without this filter the count is 6624. i verified via UI that there are users with northP domain. May 14 '15 at 20:13
  • The count is still zero. what is happening? May 14 '15 at 20:20
  • Amal: you are good. I would not have thought of that. It's case sensitive. Thank you Amal. May 14 '15 at 20:26
  • @MileyJordan You are welcome!. I also updated answer. May 14 '15 at 20:29
  • $items[$x].Delete() is throwing an error. delete with 0 argument.... May 14 '15 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.