SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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! – Codingo Apr 2 '13 at 5:00

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

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.