Is there a PowerShell or other way to get a list of all external users who were given access by link sharing to our SharePoint Online (without adding them to AD)?

frob 4,261 Reputation points
2021-12-07T23:09:00.543+00:00

Hi there

Is there a PowerShell or other way to get a list of all external users who were given access by link sharing to our SharePoint Online (without adding them to AD)?
E.g., a site owner can grant access to a document library folder by right-clicking on it > Manage Access > Share (As the Site Collection policy is set as "This site can be shared with new and existing guests").

Thanks.

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. JoyZ 18,111 Reputation points
    2021-12-17T09:31:43.563+00:00

    @frob ,

    Get reports of external users from all site collections, do you mean this? Please check as following:

    #Import SharePoint Online Management Shell  
    Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking  
       
    #Config Parameters  
    $AdminSiteURL="https://crescent-admin.sharepoint.com"  
    $ReportOutput ="C:\Temp\ExternalUsersRpt.csv"  
       
    #Get Credentials to connect  
    $Cred = Get-Credential  
       
    #Connect to SharePoint Online Tenant Admin  
    Connect-SPOService -URL $AdminSiteURL -Credential $Cred  
       
    #Get all Site Collections  
    $SitesCollection = Get-SPOSite -Limit ALL  
       
    $ExternalUsers=@()  
    #Iterate through each site collection  
    ForEach($Site in $SitesCollection)  
    {  
        Write-host -f Yellow "Checking Site Collection:"$Site.URL  
       
        #Get All External users of the site collection  
        $ExtUsers = Get-SPOUser -Limit All -Site $Site.URL | Where {$_.LoginName -like "*#ext#*" -or $_.LoginName -like "*urn:spo:guest*"}  
        If($ExtUsers.count -gt 0)  
        {  
            Write-host -f Green "Found $($ExtUsers.count) External User(s)!"  
            $ExternalUsers += $ExtUsers  
        }  
    }  
       
    #Export the Data to CSV file  
    $ExternalUsers | Export-Csv -Path $ReportOutput -NoTypeInformation  
    

    158486-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1 additional answer

Sort by: Most helpful
  1. JoyZ 18,111 Reputation points
    2021-12-08T08:24:02.343+00:00

    @frob ,

    Per my test and research, there is no such way to list all external users who are shared by sharing links.

    Currently, we can only run "Shared with external users" report on site usage page of each site collection:

    155923-image.png

    However, this report does not have columns for displaying external user information, we can only check files sharing links and type, not detailed users.
    155903-image.png

    More information for your reference:

    https://support.microsoft.com/en-us/office/view-usage-data-for-your-sharepoint-site-2fa8ddc2-c4b3-4268-8d26-a772dc55779e

    https://learn.microsoft.com/en-us/sharepoint/sharing-reports


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.