In this article I showed you how to get external users in a SharePoint Online tenant using the SharePoint Online administration. A better approach to get all the external users in a SharePoint Online tenant is by using PowerShell and the Get-SPOExternalUser cmdlet:How to get all the external users in a SharePoint Online Tenant!
############################################################################################################################################
# Script that allows to get all the external users 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 external users in a SharePoint Online Tenant.
function Get-SPOExternalUsers
{
param ($sUserName,$sMessage,$sSPOAdminCenterUrl)
try
{
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Getting all the external users in a SharePoint Online Tenant" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$msolcred = Get-Credential -UserName $sUserName -Message $sMessage
Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolcred
Get-SPOExternalUser -Position 0 -PageSize 30 | Select DisplayName,EMail | Format-Table
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Connection to Office 365
$sUserName="<YourOffice365Account>"
$sMessage="Introduce your SPO Credentials"
$sSPOAdminCenterUrl="https://<YourDomain>-admin.sharepoint.com/"
Get-SPOExternalUsers -sUserName $sUserName -sMessage $sMessage -sSPOAdminCenterUrl $sSPOAdminCenterUrl
And this is the output you will get once you run the script:
Pingback: SharePoint 2013: Resumen de posts (LXIV)! | Pasión por la tecnología...