Solved

Return all Site Collection Administrators

Posted on 2010-08-17
2
2,341 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
Comment Utility
0
 
LVL 6

Author Closing Comment

by:ThatSharepointGuy
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

12 Experts available now in Live!

Get 1:1 Help Now