1

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?

1 Answer 1

3

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.

1
  • Thank you! Works perfectly and solved a problem I struggled with for quire some time now
    – Ania
    Dec 1, 2020 at 7:41

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.