kwizcom banner advertisement

SharePoint Online: Get All Users using PowerShell

While my another post addresses How to get all users and groups in SharePoint Online, this post aims to get all users of the SharePoint site collection.

SharePoint Online: PowerShell Get All Users of the Site Collection
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Site collection URL
$SiteURL="https://crescent.sharepoint.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Initialize the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials 

#Get all users of the site collection
$Users = $ctx.Web.SiteUsers
$ctx.Load($Users) 
$ctx.ExecuteQuery()

#Get User name and Email
$Users | ForEach-Object { Write-Host "$($_.Title) - $($_.Email)"}

PowerShell to Get All Users from All Site Collections in SharePoint Online:
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

$AdminSiteURL="https://crescent-admin.sharepoint.com/"

#Connect to SharePoint Online Admin
Write-host "Connecting to Admin Center..." -f Yellow
Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential)

Write-host "Getting All Site collections..." -f Yellow
#Get each site collection and users
$Sites = Get-SPOSite -Limit ALL

Foreach($Site in $Sites)
{
    Write-host "Getting Users from Site collection:"$Site.Url -f Yellow
    Get-SPOUser -Limit ALL -Site $Site.Url | Select DisplayName, LoginName
}

Tags: sharepoint online csom get all users, sharepoint online get all users, sharepoint online powershell get all users, sharepoint online user reports, sharepoint online users list
SharePoint Online: Get All Users using PowerShell SharePoint Online: Get All Users using PowerShell Reviewed by Salaudeen Rajack on February 11, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.