Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, March 19, 2014 6:30 AM
Hello Everyone,
I'm getting this error: "You cannot delete the owners of a Web site collection" whenever I'm trying to delete a site collection administrator programmatically. Has anyone faced this issue? Can someone please suggest me a solution? Thanks.
Regards,
SC Vinod
Blog: http://sharesilver.wordpress.com/
All replies (7)
Wednesday, March 19, 2014 10:27 AM âś…Answered | 1 vote
Found the solution for this guys. You have to use the below code to remove an user as site collection admin:
SPUser invalidAdmin = web.EnsureUser(invalidUserName);
invalidAdmin.IsSiteAdmin = false;
invalidAdmin.Update();
If a primary site collection admin is getting removed then the above code will automatically assign another site collection admin as the primary site collection admin.
Regards,
SC Vinod
Blog: http://sharesilver.wordpress.com/
Wednesday, March 19, 2014 6:58 AM
Hi,
This is by design, you cannot remove a site collection administrator. A site collection Always needs a primary site collection administrator.
You can remove a site collection administrator (that is not a primary/secondary site collection administrator) with the following code:
$site = get-spsite http://url/yoursitecollection
$admins = $site.rootweb.siteadministrators
$admins.Remove("domain\username")
$admins.Update()
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Wednesday, March 19, 2014 8:18 AM
If you are part of Central Admin and have server access you can remove Site collection admin using commands given above. But if you are dont have server access then its not possible to remove these users.
Wednesday, March 19, 2014 8:30 AM
Hi, I'm making another user as a primary site collection administrator and then deleting the previous site collection administrator, even then I'm getting this error.
Regards,
SC Vinod
Blog: http://sharesilver.wordpress.com/
Wednesday, March 19, 2014 8:33 AM | 1 vote
How are you trying to achieve this. You can do this simply by using: Set-SPSite "yoursite" -OwnerAlias "domain\user". This will automatically remove the "old" site collection administrator.
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Wednesday, March 19, 2014 8:38 AM
I'm setting the site collection administrator using the below code:
SPUser ouser = web.EnsureUser(validSiteAdmins[0]);
site.AllowUnsafeUpdates = true;
site.Owner = ouser;
site.AllowUnsafeUpdates = false;
web.Update();
Below is the code to move the previous primary site collection administrator:
web.SiteAdministrators.Remove(invalidAdmin);
web.Update();
Regards,
SC Vinod
Blog: http://sharesilver.wordpress.com/
Wednesday, March 19, 2014 8:50 AM
I think SharePoint will not allow me to remove the old site collection administrator if he was the one who had created the site collection. I'm not so sure about this. Can someone clarify me on this?
Regards,
SC Vinod
Blog: http://sharesilver.wordpress.com/