Solved

Return all Site Collection Administrators

Posted on 2010-08-17
2
2,369 Views
Last Modified: 2012-05-10
Aside from some other problems that I've been having permissions wise...I wanted to see if someone else might be able to chip in on this:

I've created a web part that should display all of the site collection administrators, for each site collection within the current web application.

However, it doesn't return all of them?!

The output looks something like this:

------------------------------------------------------
SPContext.Current.Site.WebApplication.Name = MOSS_Dev

Site Name: SPSite Url=http://SERVER/SC1
    SCAdmin = DOM\sharepoint.admin

Site Name: SPSite Url=http://SERVER/SC2
    SCAdmin = DOM\sharepoint.dev
    SCAdmin = DOM\sharepoint.admin

Site Name: SPSite Url=http://SERVER/SC3
    SCAdmin = DOM\sharepoint.user

Site Name: SPSite Url=http://SERVER/SC4
    SCAdmin = DOM\sharepoint.admin

Site Name: SPSite Url=http://SERVER/SC5
    SCAdmin = DOM\sharepoint.dev
    SCAdmin = DOM\sharepoint.admin

Site Name: SPSite Url=http://SERVER/SC6
    SCAdmin = DOM\sharepoint.admin

Site Name: SPSite Url=http://SERVER/SC7

Site Name: SPSite Url=http://SERVER/SC8
    SCAdmin = DOM\sharepoint.dev
    SCAdmin = DOM\sharepoint.admin

Searched 8 Site Collections.
------------------------------------------------------

Now, "DOM\sharepoint.admin", "DOM\sharepoint.dev", and "DOM\sharepoint.user" are ALL THREE listed as Site Collection Administrators.

the "DOM\sharepoint.admin" account is listed on each site collection as an administrator when it is created, thus it shows up in Central Administration > Application Management > Site Collection Administrators list.  However, that only allows 2 SC admins.  

So, to test (because in our environment we have 8 total SC admins for all the site collections), I added "DOM\sharepoint.dev" and "DOM\sharepoint.user" to the Site Actions > Site Settings > Site Collection Administrators group on the site collections themselves.

However, the code that I've posted doesn't show any sort of "pattern" in what it displays.
All 8 Site Collections have the same settings....
"DOM\sharepoint.admin" listed as a SC Admin in Central Administration.
"DOM\sharepoint.dev" "DOM\sharepoint.user" are listed on the site collection itself in the Site Collection Administrators group.

Yet when I run this code in a web part...
"DOM\sharepoint.admin" is missing from /SC3 and /SC7.
"DOM\sharepoint.dev" is missing from /SC1, /SC3, /SC4, /SC6, /SC7.
"DOM\sharepoint.user" is missing from /SC1, /SC2, /SC4, /SC5, /SC6, /SC7, and /SC8.

I don't get why it's not returning the rest, and why it's so random?  They all have SAME EXACT SETTINGS.  It's so strange, and it's driving me crazy!

I can find no other bit of code in the SDK or MSDN other than "oUser.IsSiteAdmin" to determine if someone is in the Site Collection Administrators group.

Can anyone help?
using System;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;


namespace My.SharePoint.WebParts
{
    public class SCAdmins : Microsoft.SharePoint.WebPartPages.WebPart
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            // Get references to the web application
            SPWebApplication webApp = SPContext.Current.Site.WebApplication;
           
            // test...
            writer.Write("SPContext.Current.Site.WebApplication.Name = <b>" + webApp.Name + "</b><br/>");
            
            // Set up vars
            SPSite oSite = null;
            SPWeb oWeb = null;
            int SCCount = 0;

            // Retreive all Site Collections within webApp
            foreach (SPSite siteCollection in webApp.Sites)
            {
                // counter, just to see how many site collections it went through.
                SCCount++;
                
                // output the current site collection's name
                writer.Write("Site Name: <b>" + siteCollection + "</b><br/>");
                oSite = new SPSite(siteCollection.Url);
                oWeb = oSite.OpenWeb();

                // get collection of users in the site
                SPUserCollection userCollection = oWeb.AllUsers;
                
                // iterate through all users
                foreach (SPUser oUser in userCollection)
                {
                    // if the user is a site collection administrator
                    if (oUser.IsSiteAdmin)
                    {
                        // display his/her login name
                        writer.Write("&nbsp;&nbsp;&nbsp; SCAdmin = <b>" + oUser.LoginName + "</b><br/>");
                    }
                }
            }
            writer.Write("<br/><br/>Searched " + SCCount + " Site Collections.");
        }
    }
}

Open in new window

0
Comment
Question by:ThatSharepointGuy
2 Comments
 
LVL 12

Accepted Solution

by:
Hairbrush earned 500 total points
ID: 33462917
0
 
LVL 6

Author Closing Comment

by:ThatSharepointGuy
ID: 33559218
It doesn't exactly return all Site Collection Administrators.  The "SPSite.Owner" just shows who is listed as the site owner.  It won't show all users that are listed in CA and/or SC level Admins.

Thanks though!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now