How to get all users from SharePoint site collection using PowerShell

In this SharePoint PowerShell example we will discuss how to get all users from SharePoint site collection using PowerShell. We will also download all users in CSV format from site collection using PowerShell script.

Also, we will check a user is an admin or not in the PowerShell script in SharePoint 2016/2013. SharePoint PowerShell get all users in site collection.

You can write, run, and debug PowerShell scripts using Windows PowerShell ISE or Visual Studio code.

SharePoint 2013 PowerShell get all users in site collection

The below PowerShell script will explain, how to retrieve all users from SharePoint site collections using PowerShell and also it will display whether the particular user is an admin or a normal site user.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$siteCollURL = "http://mypc/sites/MySP2016SiteCollection"
$site = new-object Microsoft.SharePoint.SPSite($siteCollURL)
$web = $site.openweb()
$siteUsers = $web.SiteUsers
Write-Host "Site Collection URL:" , $siteCollURL
foreach($user in $siteUsers)
{
if($user.IsSiteAdmin -eq $true)
{
Write-Host "User Name: ", $user.LoginName , "Role: Admin"
}
else
{
Write-Host "User Name: ", $user.LoginName, "Role: User"
}
}
$web.Dispose()
$site.Dispose()

You can see the output after running the script.

sharepoint 2013 powershell get all users in site collection
get all users sharepoint powershell

SharePoint PowerShell get all users in site collection (without user role)

Below is another PowerShell script that will display all users from SharePoint 2016 site collection without role.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$siteCollURL = "http://mypc/sites/MySP2016SiteCollection"
$site = new-object Microsoft.SharePoint.SPSite($siteCollURL)
$web = $site.openweb()
$siteUsers = $web.SiteUsers
Write-Host "Site Collection URL:" , $siteCollURL
foreach($user in $siteUsers)
{
write-host $user.LoginName
}
$web.Dispose()
$site.Dispose()
sharepoint 2013 powershell get all users in site collection
SharePoint powershell script to list all users in all groups

Download all Users from SharePoint site collection using PowerShell

By using the below PowerShell script, you will be able to download all users (CSV format) from SharePoint 2016/2013 site collection using PowerShell script.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$siteCollURL = "http://mypc/sites/MySP2016SiteCollection"
$site = new-object Microsoft.SharePoint.SPSite($siteCollURL)
$web = $site.openweb()
$siteUsers = $web.SiteUsers
Write-Host "Site Collection URL:" , $siteCollURL
$Output = foreach($user in $siteUsers)
{
New-Object -TypeName PSObject -Property @{
UserName = $user.LoginName
} | Select-Object UserName
}
$Output | Export-Csv E:\AllUser.csv -NoTypeInformation -Force
$web.Dispose()
$site.Dispose()

Also, you can read some more PowerShell SharePoint examples below:

Conclusion

I hope this article will be helpful to get all users in a site collection in SharePoint using PowerShell. We have seen here sharepoint PowerShell get all users in a site collection and how to download all users in CSV format from site collection using PowerShell in SharePoint 2016/2013.

>