Question

I'd like to make a report of all sites in all of my web applications, and store site owners in one of columns. I am using PowerShell.

I can retrieve the owners using $Root.AssociatedOwnerGroup.Users
The problem is that when I try to create a SPUserValue object, to store it the People and Groups column, it requires a user ID, which is relative to the site.

Is it possible to store user information from different sites, or even web applications?

Was it helpful?

Solution

I would look into using SPWeb.EnsureUser(loginName) (documentation here, although it's not super informative on its own).

That method will create a new SPUser object for the site where you are trying to save all those values to your custom list, if it does not exist already, or return the existing SPUser object if it does already exist on that site.

That way you can get the user ID values that are specific to that site in order to make your SPUserValue objects.

Technically you will be "adding" all those users to the site where you are trying to collect the reporting information, but IIRC using EnsureUser does not grant those users any permissions, it just adds them to the SiteUsers collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top