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 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()

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:
- PnP PowerShell Commands for SharePoint Online List
- PnP PowerShell commands for SharePoint Online Site
- Get SharePoint document library size using PowerShell
- SharePoint Online Automation: Upload Files Remotely to SharePoint Online Document Library using PowerShell
- What is PowerShell variable
- SharePoint 2013 backup and restore using PowerShell
- SharePoint Online storage limits
- How to send email using PowerShell in Office 365
- PowerShell find files modified in last N days
- Insert/Add item to SharePoint Online list using PowerShell
- Delete list items created before N days using PowerShell in SharePoint Online
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.
I am Bijay a Microsoft MVP (8 times –Â My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com