Search in SharePoint Online returns both internal and external users by default. This may not be desirable. Here’s how to exclude external users from the search results.
External users have account names containing #ext# which makes them easy to filter out. Typically when you search for people you will query against the Local People Results result source. In SharePoint Online we can’t modify this result source like On Premises, but we can clone it and add our own custom filters:
- Open SharePoint Admin
- Go to search settings and select Manage Result Sources
- Copy Local People Results (click the down arrow to find the copy command)
- Edit your new result source and find Query Transform
- Add -AccountName:"#ext#" to the query
- Verify that it works using the Query Builder
Remember that you will need to configure search pages and other solutions to use this new result source instead of the default Local People Results!