Pregunta

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()
¿Fue útil?

Solución

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()
Licenciado bajo: CC-BY-SA con atribución
scroll top