I would like to output the users of a group, for 40 groups, or for every group within the SharePoint Portal. I would like to do this programatically through powershell or a command line tool for the benefit of getting users in Textual Form for reporting purposes, or another means that provide textual output.

Can some one point me in the right direction?


Here you have fully functional PS script:

Add-PsSnapin Microsoft.SharePoint.PowerShell

$siteUrl = "http://mycoolsite"
$web = Get-SPWeb $siteUrl

@(foreach ($group in $web.SiteGroups) {
  foreach($user in $group.Users) {
    $usergroup = New-Object System.Object
    $usergroup | Add-Member -type NoteProperty -name GroupName -value $group.Name
    $usergroup | Add-Member -type NoteProperty -name UserName -value $user.Name

     Write-Output $usergroup 
}) | Export-Csv userlist.csv -NoTypeInformation

Output will be userlist.csv file with 2 columns Group Name, User Name

  • I tried to run this: I received a continuous popup powershell window that would open and close until I hit Ctrl + C , and unfortunately I do not know how to resolve it. Also I am wondering how I could get the ACLs for the groups without somewhere providing my credentials in this script.. is it going to use SSO? – sammarcow Mar 6 '12 at 22:55
  • I have updated my script addin SharePoint Snapin at start. However I must point out few things (by looking at othere answers here and your otehr questions on this site): this powershell script will work on MOSS 2010, must be run on server where SP is installed, user must have permissions to read users from groups - simplest way is to run it as site collection admin or farm admin. – Vedran Rasol Mar 7 '12 at 9:34
  • i was unclear in stating that this is MOSS 2007. We have about 300 external users (clients). Is there any way to accomplish this before upgrading to MOSS2010? Will it work on MOSS 2010 with the Foundation edition? – sammarcow Mar 7 '12 at 18:09
  • Thanks Vedran. I copied the script and changed only the site URL and it worked flawless. Got the CSV file with group and user name columns. Swanl – Swan Lee Nov 30 '12 at 22:19

You could create a console application for SharePoint. in VS2010 An example for all groups would be:

using (SPSite site = new SPSite("http://yoursiteurl"))
  using(SPWeb web = site.OpenWeb()) 
    foreach(SPGroup grp in web.SiteGroups) 
      foreach(SPUser usr in grp.Users) 
        string sGroupName = grp.Name;
        string sLogin = usr.LoginName;
        string sName = usr.Name;
        string sEmail = usr.Email;
        int uId = usr.ID;
        //Output the user info here 

If you need this for reporting services, you could create Linq to SQL classes or Entity Framework to write directly to some database that would serve as a source for reporting services.

  • I received a message: You do not have Sharepoint installed on this server. We have it installed on a dedicated server, but that server has VS2005. Is there any way around this? I don't see why people developing applications for sharepoint would be doing them directly on the production server anyway.. – sammarcow Mar 7 '12 at 0:40
  • 1
    No developing on a production server is absolutely not recommended. What you can do is set up a development environment on another computer as described here – Gomiunik Mar 7 '12 at 6:44
  • Will this work with MOSS 2007? – sammarcow Mar 7 '12 at 18:11
  • I could make it on MOSS2k7 – Gomiunik Mar 7 '12 at 21:03

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.