I have an auditing / documentation requirement around my SP Environment upon which members of specific groups need to be listed. Now, rather than doing this manually via screen-shots and / or cut and pastes, I'd like to set-up a utility in PS that'll do this for me and can be referred to in the literature.

To this end, I'd like to create a PowerShell script that will take the name of a user group and will output the members of that group into a file.

I've got a few scripts that output user groups and all users per site collection but nothing that allows me to be more surgical in targeting a specific group at a time.

As such, if anyone has a script or a reference to one that I can toy with, I'd appreciate it.

1 Answer 1


First create your script and save it to a file such as ListAllUsersInGroup.ps1

$site = Get-SPSite <UrlToSiteCollection>
$groups = $site.RootWeb.sitegroups

foreach ($group in $groups) 
    if ($group.name -eq "My Group")
        foreach ($user in $group.users) 
            "  User: " + $user.name


Then you can run the script doing the following letting the output go to file.txt like this

PS > .\ListAllUsersInGroup.ps1 > file.txt

This outputs the result in the same location as your script with the desired information:

enter image description here

  • 1
    Perfect. I thought piping would sort it but this works perfectly. Apr 10, 2013 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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