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

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

$site.Dispose()

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

share|improve this answer
1  
Perfect. I thought piping would sort it but this works perfectly. –  Steven D Andrews Apr 10 '13 at 10:30
    
@StevenDAndrews Thanks! Glad I could help! –  Benny Skogberg Apr 10 '13 at 10:51

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.