Hello Everyone,
Below is the Powershell script to get all external users from office 365 tenant.
#---------------------------------------------------------------------------------------------------------------------------
$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="Enter SPO Credentials"
$sSPOAdminCenterUrl="https://<YourDomain>-admin.sharepoint.com/"
Get-SPOExternalUsers -sUserName $sUserName -sMessage $sMessage -sSPOAdminCenterUrl $sSPOAdminCenterUrl
Comments
Post a Comment