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
Solved

Return all Site Collection Administrators

Posted on 2010-08-17
2
2,403 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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