Powershell script for SharePoint to list all users in all groups

I needed a quick result without using any thirdparty applications to find all users in all groups of a SharePoint web application.

I found a great powershell script from this site that did just the trick for SharePoint 2007 and SharePoint 2010

http://techtrainingnotes.blogspot.com/2010/12/sharepoint-powershell-script-to-list.html

For both SharePoint 2007 or 2010 in any PowerShell:

<pre>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("http://yourservername/sites/yoursitecollection ")
$groups = $site.RootWeb.sitegroups
foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {"  User: " + $user.name} }
$site.Dispose()</pre>
<pre>

or for SharePoint 2010 in the SharePoint 2010 Management Shell:

<pre>$site = Get-SPSite http://yourservername/sites/yoursitecollection
$groups = $site.RootWeb.sitegroups
foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {"  User: " + $user.name} }
$site.Dispose()</pre>

Simply change the web application to point to your site and save the script to a ps1 file. To get the script to dump the info to a file do the following.

script.ps1 > File.txt

That should dump all the permissions to file.txt in the directory you are running script.ps1 from.

Post to Twitter

2 comments

  1. […] This post was mentioned on Twitter by Alistair Pugin. Alistair Pugin said: RT @bradgcoza: I just posted Powershell script for SharePoint to list all users in all groups, read it here: http://www.bradg.co.za/?p=90 […]

  2. Rich says:

    This script for 2010 will get the info from the root site collection. Is it possible to get them for each subsite as well?

    Thanks!

Leave a Reply