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?

$SITE = GET-SPSITE "HTTP://siteurl/site"

$I = $LIST.ITEMS | WHERE {$_["ACCOUNT"] -Like '*NorthP\*'}

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

  • 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. – Miley Jordan May 14 '15 at 20:13
  • The count is still zero. what is happening? – Miley Jordan May 14 '15 at 20:20
  • Amal: you are good. I would not have thought of that. It's case sensitive. Thank you Amal. – Miley Jordan May 14 '15 at 20:26
  • @MileyJordan You are welcome!. I also updated answer. – Amal Hashim May 14 '15 at 20:29
  • $items[$x].Delete() is throwing an error. delete with 0 argument.... – Miley Jordan 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.