0

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?

1

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

0

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;
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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