SharePoint: List Users with Access to an SPSite or SPList using PowerShell
Here's a PowerShell script to get a listing of all users on a SharePoint site and on a SharePoint list using a PowerShell script. It's a small script file which you can download from the TechNet Library.
Script consists of two functions:
GetSPWebUsers
GetSPAllSPUsers
Get all SPWeb Users
Using this, you can get a list of all site users. It will take asingle parameter (i.e site URL):
function GetSPWebUsers($SiteCollectionURL)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$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()
}
Get All SPList Users
This function will return a list of all users and their permission set for any list/library. This can be used to check user permissions against a list. This function have two parameters (i.e. site URL and List Name):
function GetSPAllSPUsers($SiteCollectionURL,$SPListName)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)
$web = $site.openweb()
$list = $web.Lists[$SPListName]
$siteCollUsers = $web.SiteUsers
foreach($user in $siteCollUsers)
{
Write-Host " ------------------------------------- "
Write-Host "Site Collection URL:", $SiteCollectionURL
if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$user) -eq $true)
{
Write-Host "User : ", $user.LoginName
Write-Host "Assigned Permissions : ", $list.GetUserEffectivePermissions($user.LoginName)
}
Write-Host " ------------------------------------- "
}
$web.Dispose()
$site.Dispose()
}
Other Languages
This article is also available in the following languages: