0

I'm trying to add a user as a 'Secondary Site Collection Administrator' using the following PowerShell script :

Get-SPSite -Limit All | %{Set-SPSite $_ -SecondaryOwnerAlias "i:0#.w|contoso\adminuser"}

when it runs it says the user cannot be found. I've tried 'i:0#.w|contoso\adminuser' and 'contoso\adminuser' and still the same. This fails to add the user as a secondary collection administrator. I have noticed one thing with this script. These are the steps :

  1. Add 'contoso\adminuser' as a secondary collection administrator through the UI. click ok. redirects back to the central admin page.
  2. Go back in and remove 'contoso\adminuser' from the secondary collection owner and click ok redirects back.

If I run the script again it works, it adds the user as a 'secondary collection administrator'

Do I need to add this user to the site first as a limited user or something else?

I just want to add the user to all site and sub collections.

EDIT 'contoso\adminuser' has been imported from Active Directory. If I create a new site and try and run the script again it will not add the user to the site collection. To get the script to work I have to add and the remove the user through the UI. I then run the script and it adds the user as a secondary collection owner but still gives me the error user does not exist.

I have come across cases in SharePoint Online. I think the user needs to be added some how as a Limited Access.

Another test I have just done is by sharing a folder in the team site with read permissions. Once I did that and ran the script it added the user as a secondary collection administrator

enter image description here

5
  • No issues here using your code. On the Jan 2017 PU.
    – user6024
    Jan 30, 2017 at 17:34
  • Does it work first time if you create a new site?
    – Webfort
    Jan 30, 2017 at 17:36
  • @Trevor, could you please try with a user who is not in sharepoint...brand new user...i think i got this error
    – Waqas Sarwar MVP
    Jan 30, 2017 at 17:36
  • It works just fine with a new user. Created one in AD, then ran through this code, including on a site that had no secondary user previously.
    – user6024
    Jan 30, 2017 at 17:49
  • I've just added more information and another test
    – Webfort
    Jan 30, 2017 at 17:51

1 Answer 1

0

Sounds like the user may not exist in that site collection yet. Try using EnsureUser to ensure the user exists, then add as Secondary Site Collection Administrator.

Get-SPSite -Limit All | % {
    $_.RootWeb.EnsureUser("contoso\adminuser")
    Set-SPSite $_ -SecondaryOwnerAlias "contoso\adminuser"
}

Hope this helps!

8
  • How do I get the user to exist in a new site collection? Can I add the user? Thanks
    – Webfort
    Jan 30, 2017 at 17:54
  • The EnsureUser method will automatically add the user if necessary. Jan 30, 2017 at 17:56
  • This isn't necessary to do. Setting the SCA brings in the user from AD when you set it.
    – user6024
    Jan 30, 2017 at 17:58
  • It doesn't appear to be adding it and so not adding it as a secondary collection admin. Is there anything else I can check?
    – Webfort
    Jan 30, 2017 at 18:01
  • The above works on the root url ie http:://sp2016/ but not on any subsites sp2016/sites/new site
    – Webfort
    Jan 30, 2017 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.