Skip to content
Menu
SharePoint Gems
  • Power Platform
  • Development
    • SharePoint 2013
  • Migration
  • Administration
  • SP Online
  • Contact
  • About
    • Privacy Policy
SharePoint Gems

Retrieve all users from Site Collection using PowerShell

Posted on October 6, 2020September 29, 2021

Hello SharePointer,
Today, in this article we will see how to retrieve all users from site collection using PowerShell.

This tutorial will guide you to retrieve users from SharePoint on-premise as well as SharePoint Online. we also might need to download a list of users in CSV format.

Contents hide
1 For SharePoint On-Premise
2 PowerShell to get all users in SharePoint Site Collection
3 Download all users from SharePoint site collection using PowerShell
4 For SharePoint Online
4.1 Share this:
4.2 Like this:
4.3 Related

For SharePoint On-Premise

In below few code Snippets we will see, How to get all users from SharePoint Site Collection.

PowerShell to get all users in SharePoint Site Collection

Below is the PowerShell that will display all users from SharePoint Site Collection on screen.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$siteCollURL = "http://<your sitecollection URL>"
$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 a below PowerShell Script, you can download all users from SharePoint site collection in CSV formatted file.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$siteCollURL = "http://<your site collection URL>"
$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()

For SharePoint Online

In this section, we will see how to get all users from SharePoint Online site collection using PowerShell.

There are multiple methods or ways to retrieve all users from SharePoint Online site collection. These are described as below.

  1. Using SharePoint Online Management Shell (SPO) PowerShell scripts
  2. with the CSOM scripts and
  3. Using PnP PowerShell

In this tutorial, we are going to retrieve users from the SharePoint Online site using PnP PowerShell.

Below is the code to get all users using Pnp-PowerShell.

$SiteURL = "https://<your-tenant>.sharepoint.com/sites/HRD"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Get All users of the site collection
Get-PnPUser

This will list all the users as below.

Retrieve all users from Site Collection using PowerShell

These are the ways to list all users from SharePoint Site Collection using PowerShell.

Also, you can find some More PowerShell script examples related to SharePoint.

  • Retrieve all Communication Sites using PnP PowerShell
  • SharePoint Online: Delete Folders using PnP PowerShell
  • How to Convert Site Page into News Post in SharePoint Online?
  • Programmatically Upload a File in SharePoint Document Library.
  • PowerShell to create Team Site in SharePoint Online
  • Create a Communication Site using PowerShell
  • Move SharePoint Online Files with PowerShell
  • SharePoint Administrator Interview Questions
  • MS-Flow Interview Questions and Answers

I hope you find this article interesting, If yes then please let me know by user comments below.

Share this:

  • Print
  • Twitter
  • Facebook
  • LinkedIn
  • WhatsApp
  • Telegram
  • Pinterest
  • Reddit

Like this:

Like Loading...

Related

2 thoughts on “Retrieve all users from Site Collection using PowerShell”

  1. Pingback: Delete all items from SharePoint list with CSOM - SharePoint Gems
  2. Pingback: PnP PowerShell to get all Site Collections - SharePoint Gems

Leave a ReplyCancel reply

  • Development
  • Migration
  • Poweer Apps
  • Power Automate
  • Power Platform
  • SharePoint 2013
  • SharePoint Administration
  • SharePoint Online
  • Tips
  • Uncategorized

Best of Computers

Blog Stats

  • 67,509 hits

Subscribe

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,433 other subscribers
Buy Me Coffee
©2025 SharePoint Gems | Powered by WordPress and Superb Themes!
%d