SharePoint: Get list of all users using PowerShell script

I was having a requirement to get list of all users which have permissions on a sharePoint site and also on any specific list using PowerShell script. You can download script file from Technet Gallery.

Open Windows PowerShell Integrated Scripting Environment, and copy below script.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null
$SiteCollectionURL = “http://sp2013:1111″
$site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)
$web = $site.openweb()
$siteUsers = $web.SiteUsers

foreach($user in $siteUsers)
{
Write-Host ” ————————————- ”
Write-Host “Site Collection URL:”, $SiteCollectionURL
if($user.IsSiteAdmin -eq $true)
{
Write-Host “ADMIN: “, $user.LoginName
}
else
{
Write-Host “USER: “, $user.LoginName
}
Write-Host ” ————————————- ”
}
$web.Dispose()
$site.Dispose()

The output of above script will be like this

users Powerscript

To fetch users listing for any specific list with user roles, you need to do below given modifications in listed code.

$list = $web.Lists[“Custom List”]
$siteCollUsers = $web.SiteUsers
foreach($MyUser in $siteCollUsers)
{
Write-Host ” ————————————- ”
Write-Host “Site Collection URL:”, $SiteCollectionURL
if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$MyUser) -eq $true)
{
Write-Host “User : “, $MyUser.LoginName
Write-Host “Assigned Permissions : “, $list.GetUserEffectivePermissions($MyUser.LoginName)
}
Write-Host ” ————————————- ”
}

Above script will print the user login names and permissions assigned on SharePoint List.

The following two tabs change content below.
Adnan Amin
Adnan is an active SharePoint MVP and having over 11 years of extensive experience with major expertise on SharePoint Server, office 365, .Net Platform and Microsoft BI, Adnan is currently working as SharePoint Architect at FMT Consultants. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past seven years and worked on different intranet/intranet solutions for private & govt. sector majorly in United States and Gulf region, which include OOB and customized solutions. He is a trainer, technology evangelist and also speaks in community forums.

One Comment

  1. Hi,

    I want to retrieve a list of all users, which have access on a SharePoint site, sub site, lists & libraries.
    The report should consist of username, his access level & name of site/list/library.
    Please can you share a script for this.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *