Brian MOSS Stark

A rolling MOSS gathers no stones.

Blog

Get all users and roles, SharePoint 2010

Posted by Brian Stark on July 11, 2011 at 6:33 AM

Recently I was tasked to get a list of all users in a portal and the roles and groups.

The below powershell script was taken from the following link
http://mkdot.net/blogs/darko/archive/2010/10/01/get-users-permissions-list-on-sharepoint-webs-powershell-script.aspx

 

Just copy and paste the following script into powershell.

function Get-UsersWebPermissions([string]$portalurl, [String[]]$excludewebs, [string]$onesite) {

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

if (-not $portalurl.EndsWith("/")) { $portalurl = $portalurl + "/" }

foreach ($spService in $farm.Services) {

if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {

continue;

}

foreach ($webApp in $spService.WebApplications) {

if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }

$webAppUrl = $webApp.GetResponseUri('Default').AbsoluteUri

if ($webAppUrl.ToUpper() -eq $portalurl.ToUpper()){

foreach ($site in $webApp.Sites) {

#if onesite parameter is present

if (($onesite -ne $null) -and ($onesite -ne ""))

{

#check does this is the only one selected web for processing

if ($site.Url.ToUpper() -ne $onesite.ToUpper()) { continue }

}

foreach ($web in $site.AllWebs) {

#check does web is excluded for listing

if ($excludewebs -contains $web.Url) {

Write-Host "skipping excluded web" $web.Url

continue

}

foreach ($user in $web.SiteUsers){

#do not list System account sharepoynt\system

if ($user.Loginname.StartsWith("SHAREPOINT\")) {continue}

$data = @{

"Site" = $site.Url

"Web Url" = $web.Url

"Web Name" = $web.Title

"Username" = $user.Loginname

"Fullname" = $user.Name

"Roles" = $user.Roles

"Groups" = $user.Groups

}

New-Object PSObject -Property $data

}

$web.Dispose();

}

$site.Dispose()

}

}

}

}

}

 

#1 Usage: lists webs and users on web application http://portal, but processes users and permissions only on test web

Get-UsersWebPermissions -portalurl:http://portal/ -onesite:http://portal/sites/test | Out-GridView

#2 Usage: lists webs and users on web application http://portal, but excludes 3 webs/sites: expenses, Docs and SiteDirectory

Get-UsersWebPermissions -portalurl:http://portal/ -excludewebs:@('http://portal/expenses','http://portal/Docs','http://portal/SiteDirectory') | Out-GridView

#3 Usage: process web application http://portal with all webs and users

Get-UsersWebPermissions -portalurl:http://portal/ | Out-GridView

Categories: MOSS

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

Already a member? Sign In

0 Comments