I want to be able to find out what an user has access to throughout the site in SharePoint online. There are few articles on line on doing that on onprem but not for SharePoint online site. Has anyone has any article they would like to share or simply let me know how do i tackle this task.
1 Answer
For SharePoint online, you can retrieve users from the sites using Get-SPOUser command.
Here is a demo to get users from all site collections in SharePoint Online tenant:
#################################################################
# 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>" | Out-File "C:\Users\Administrator\Downloads\SharePoint Online\Users.txt" -Append;
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Connection to Office 365
$sUserName="<user account>"
$sMessage="SPO Credential Please"
$sSPOAdminCenterUrl="https://<Domain>-admin.sharepoint.com"
#Get-SPOUser -Site "https://<Domain>.sharepoint.com/" -LoginName "<user>"
Get-SPOUsersAllSiteCollections -sUserName $sUserName -sMessage $sMessage
Some articles about how to use PowerShell to get users and groups in SharePoint Online:
https://gallery.technet.microsoft.com/office/How-to-get-all-the-users-3bc917b0
Introduction to the SharePoint Online Management Shell cmdlet.