Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

For our audit process I need to regularly capture all of our SharePoint role groups (for our main site collection) and the members in each group. Is there a reliable way to approach this problem?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I would use the powershell commands to write out each SPGroup (using SPWeb.SiteGroups) and then writing out each member of the group.

share|improve this answer
    
Thanks, this did it! Posted my proof below! –  ElvisLikeBear Apr 2 '13 at 5:00
add comment

Solved using advice from Ryan Erickson, my proof (note: just a proof, hence sloppish standard code) is below (also not PowerShell as suggested since I'm more comfortable C# but it should be relatively easy to convert):

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;


namespace QIC.RE.SharePoint.Permissions.ConsoleApplication
{
    class Program
    {

        static void Main(string[] args)
        {
            string siteCollection = "http://dev/re";

            string version = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();

            Console.WriteLine("[{0}] SharePoint Permissions started with version '{1}'.", DateTime.Now.ToShortTimeString(), version);

            try
            {
                using (var site = new SPSite(siteCollection))
                {
                    using (var web = site.OpenWeb())
                    {
                        foreach (SPGroup group in web.Groups)
                        {
                            Console.WriteLine("\n[{0}] Group: '{1}'.", DateTime.Now.ToShortTimeString(), group.Name);
                            Console.WriteLine("###########################");

                            if (group.Users.Count > 0)
                            {
                                foreach (SPUser user in group.Users)
                                {
                                    Console.WriteLine("\n[{0}] Username: '{1}'", DateTime.Now.ToShortTimeString(), user.Name);
                                    Console.WriteLine("\n[{0}] Login Name: '{1}'", DateTime.Now.ToShortTimeString(), user.LoginName);
                                    Console.WriteLine("\n[{0}] E-mail: '{1}'", DateTime.Now.ToShortTimeString(), user.Email);
                                    Console.WriteLine("\n[{0}] User ID: '{1}'", DateTime.Now.ToShortTimeString(), user.ID);
                                }
                            }
                            else
                            {
                                Console.WriteLine("[{0}] Group: '{1}' is empty.", DateTime.Now.ToShortTimeString(), group.Name);
                            }

                            Console.WriteLine("\n###########################");
                        }
                    }
                }
            }
            catch (Exception)
            {

                Console.WriteLine("[{0}] Error: Unable to open site '{1}'.", DateTime.Now.ToShortTimeString(), siteCollection);
                throw;
            }
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.