Script That Allows to Get All the Users for All the Site Collections in a SharePoint Online Tenant

In this video for Developers Senthamil Selvan will show how to get the users from the SharePoint Online site collection / sites using PowerShell script. The SPO Management shell has API to get all the users from all the sites in the SharePoint online.

You will learn:
1. Learn prerequisite needed for SPO Management Shell to be installed
2. PowerShell scripting using the SPO Management Shell
3. How to get all users from SharePoint Online Site

Script

#################################################################
# Script that allows to get all the users for all the Site Collections in a SharePoint Online Tenant
# Required Parameters:
# -> $sUserName: User Name to connect to the SharePoint Admin Center.
# -> $sMessage: Message to show in the user credentials prompt.
# -> $sSPOAdminCenterUrl: SharePoint Admin Center Url
##################################################################

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that gets all the site collections information in a SharePoint Online tenant
function Get-SPOUsersAllSiteCollections
{
param ($sUserName,$sMessage)
try
{
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Getting the information for all the site colletions in the Office 365 tenant" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$msolcred = get-credential -UserName $sUserName -Message $sMessage
Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolcred
$spoSites=Get-SPOSite | Select *
foreach($spoSite in $spoSites)
{
Write-Host "Users for " $spoSite.Url -foregroundcolor Blue
Get-SPOUser -Site $spoSite.Url
Write-Host
}
Write-Host "Getting users" -ForegroundColor Green
##Get-SPOUser -Site "<SITECOLLECTION URL HERE>" | Out-File "C:UsersSenthamilDownloadsSharePoint OnlineUsers.txt" -Append;
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

#Connection to Office 365
$sUserName="UID@domain.onmicrosoft.com"
$sMessage="SPO Credential Please"
$sSPOAdminCenterUrl="https://<DOMAIN>-admin.sharepoint.com/"

Get-SPOUsersAllSiteCollections -sUserName $sUserName -sMessage $sMessage

About the author Senthamil Selvan: 

Senthamil SelvanI am a Windows Consumer Apps MVP. http://mvp.microsoft.com/en-us/mvp/Senthamil%20Selvan-5000687. I have experience in developing multiple Universal Apps to the Windows store. My work experience is mainly on SharePoint and O365 environment. Below are some of my apps deployed to the Windows Store.

1. SEA SPC 2014 – South East Asia SP conference 2014. I developed this app for the conference which was held in Singapore 25th Nov 2014. I was a speaker.
2. Math Formulas
3. Ultimate Cryptex
4. SG Things to do
5. SG Parking (WP 8 App)

Check out last years European SharePoint Conference video:

European SharePoint Conference 2015 takes places in Stockholm Sweeden from 9-12 November 2015. View Programme>>

 

Share this on...

Rate this Post:

Share: