Viewing Sharepoint Groups and Group Membership
-
Thursday, June 21, 2012 8:42 PM
I created the following to view\export all groups\group members from a sharepoint site.
Function Get-SPGroups {
Param(
[Microsoft.Sharepoint.Powershell.SPWebPipeBind]$Web
)
$SPWeb = $web.Read()
$SPWeb.SiteGroups | Select Name,Users | Out-File C:\file.txt
}
Get-SPGroups -web "http://siteurl"
The output looks like this:
Name Users
---- -----
Approvers {CONTOSO\andyj, CONTOSO\annal, CONTOSO\annew, CONTOSO\domai...I'd like to see all users but am limited to the first 4. I've tried setting the $FormatEnumerationLimit to 10 but same results. I've tried using Export-Csv but it only displays "Microsoft.Sharepoint.SPUserCollection" as the users object. Any ideas on how to expand all the users? I'd also like to use Export-Csv but would need to find a way to expand the SPUserCollection object as well.
Thanks,
Joe
All Replies
-
Friday, June 22, 2012 7:43 AMModerator
Hi,
Please try below code:
$groups=$SPWeb.SiteGroups | Select Name foreach($group in $groups) { $GroupName = $_.Name $GroupMembers = ($_.Name).Users foreach($user in $groupmembers) { New-Object PSObject -Property @{ Group = $GroupName Name = $_.Name } } }Hope the below link be helpful:
SharePoint: PowerShell Script to List All Users in All Groups
http://techtrainingnotes.blogspot.com/2010/12/sharepoint-powershell-script-to-list.html
Regards,
Yan Li
If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.
Yan Li
TechNet Community Support
- Marked As Answer by Yan Li_Microsoft Contingent Staff, Moderator Monday, June 25, 2012 9:55 AM
-
Friday, June 22, 2012 2:54 PM
Yan Li,
Thanks for the assist. The code you posted however doesn't work as expected. The first issue I noticed was in the Foreach construct. I believe you meant to use $Group.Name instead of $_.Name. That was easy enough but the other issue was with the $GroupMembers = ($Group.Name).Users. For some reason that variable is empty so the table that is produced contains the groups but the user column is empty. I read the blog article and with a few edits got it to work.
$array = @() $spweb = Get-SPWeb "http://demo2010a:100" $Groups = $SPWeb.SiteGroups Foreach ( $Group in $Groups ) { $GroupName = $Group.Name Foreach($User in $Group.users) { $obj = New-Object PSObject -Property @{ GroupName = $GroupName UserName = $User.Name } $array += $obj } } $array
Thanks
Joe
- Marked As Answer by Yan Li_Microsoft Contingent Staff, Moderator Monday, June 25, 2012 9:55 AM

