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 :
- Add 'contoso\adminuser' as a secondary collection administrator through the UI. click ok. redirects back to the central admin page.
- 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