Skip to content

Instantly share code, notes, and snippets.

@junecastillote
Created August 18, 2023 17:58
Show Gist options
  • Save junecastillote/a32de73202f8a5ed3da2e0b8b09b4d9f to your computer and use it in GitHub Desktop.
Save junecastillote/a32de73202f8a5ed3da2e0b8b09b4d9f to your computer and use it in GitHub Desktop.
Get All External Users on Individual SPO Sites
#Get_SPO_External_Users.ps1
# Specify the SharePoint Online site URL.
$siteUrl = 'https://lazyexch.sharepoint.com/sites/CustomerSupportPortal'
# Initialize the results placeholder arraylist
$externalUsers = [System.Collections.ArrayList]@()
# Set the initial position index to 0 (zero-based index).
$positionIndex = 0
# Execute the do-while loop to get all external SharePoint users exceeding 50.
do {
# Get the SharePoint Online external users from $positionIndex, maximun of 50.
$temp = @(Get-SPOExternalUser -SiteUrl $siteUrl -PageSize 50 -Position $positionIndex)
# If the last retrieved external users count is not 0, add it to the $externalUsers collection.
if ($temp.Count -gt 0 ) {
$null = $externalUsers.AddRange($temp)
}
# Increment the position index by 50, the maximum page size
$positionIndex += 50
}
while (
# Continue the loop if the last retrieved external users count is 50
$temp.Count -eq 50
# Otherwise, exit the loop.
)
# Display the results
$externalUsers | Select-Object DisplayName, Email, AcceptedAs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment