Solved

Return all Site Collection Administrators

Posted on 2010-08-17
2
2,464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

622 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