List of all users having access to at least one site in the site collection

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/32040

  •  07-12-2019
  •  | 
  •  

Вопрос

I want to retrieve all the users who are having any access to at least one site in a site collection. I tried using 'SPWeb.SiteUsers' and it gave me almost what i wanted. The only exception was - it also returns me the users which once had permission one some site, but their permission were revoked later.

Is there a way to get all active users having access to at least one site in a given site collection ?

Это было полезно?

Решение

There is no way to get that list. SharePoint don't even know it.

SiteUsers is the closest, but as you've already found out it includes users who has had access to a site (or items on a site) (and have used that access). But it doesn't include users who have access due to a group membership, but haven't used that access yet.

So the best would be to look in the governance document specifying who has access. ;-)

Другие советы

SharePoint knows that list. At least SharePoint knows which users have explicit access, which users have access via a SharePoint group, and which AD security groups have access ( either explicitly or via a SharePoint group... ).

Knowing this, you can browse all the SPSite's SPWebs ( SPSite.AllWebs ), then browse each SPWeb's SPUsers ( SPWeb.SiteUsers contains that list ), then, if the SPUser is an AD security group ( IsDomainUser == true ), you can use a third party Active Directory Add-On to browse the AD group recursively for all users within it ( check out the powershell Get-ADGroupMember cmdlet if your server farm supports it - but there are other ways to do it ).

During the browsing process ( before expanding into the AD security group tree ), you can access each SPUser's permission using the SPWeb object ( SPWeb.GetUserEffectivePermissionInfo() ) and filter the SPUsers which don't have the required permissions.

In practice, you won't get a SPUser object instance for each user having access to your site, but you will get an exhaustive list of logins & other substantial infos matching this criteria (depending on your third party tool for browsing the AD).

SPWeb.SiteUsers will fetch you all the users in that Site Collection.

SPWeb.Users is what you are looking for. It should fetch you all the active users of a perticular site.

http://weblogs.asp.net/bsimser/archive/2006/03/13/440169.aspx

Another thing that’s interesting is that if you did add “spsuser” to the site manually he would show up in the SPWeb.Users list above. However if you removed him, he would vanish from SPWeb.Users but he would still show up in the SPWeb.SiteUsers list. His ID # is reserved so the next user you added manually would have an ID of #6 (in the case of the site) and if you re-added “spsuser” at a later date, he would re-appear in both lists with an ID of #5.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top