One of the great features in Office 365 is external sharing. It allows you to quickly share content with users outside your organization. However once an external user logs into the SharePoint by opening the document, he or she will show up in the search results. Each external user that has once logged in to the system will have a user account present in the People result source. This feature allows for you to easily search for people and find them. However it also can also cause some clutter. If you are considering on inviting lots of people they all show up in the people search result source.
If you are running with a lot of external users and you want to distinguish between external and internal users you are faced with some problems. In a recent case a client decided to use ‘exclude’ all their external contacts. This so that their internal accounts could use the people search and find colleagues without being faced with thousands of external accounts. Unfortunately there is no way easy way to exclude external contacts. If you are running a single domain you could use the domain name. By including everyone with the same domain name you can exclude everyone else.
In our case however we had over 30 different domains. That means it is not an option to include only the domain you like into the result source. Luckily external accounts have a slightly different naming convention as normal users. While normal users have the option to edit their profile, external users cannot change their preferred name. All external users will have their e-mail account (used for logging in) as their preferred name. As all of our external accounts where either @hotmail.com or @live.nl we decided to exclude all those accounts. By using the preferred name to exclude all accounts that contained either a .com or a .nl in their name we where able to exclude all external accounts. We came up with the following query
Besides that each Office 365 contains at least two search accounts that will show up in the people results. The _spocrawler and the _spoapp these accounts can be excluded as well.
Warning: there are a few tenants that I have seen where the account was not _spo but something similar. It seems that the naming convention for crawler accounts is not limited to _spocrwaler but can also be _spo_crawler. So there might be a risk that there other options too.
So in order to exclude external accounts we ended up changing the results web part. This web part allows you to extend the query, and thus we changed the Query Text as seen in the screenshot below.
Extending the query would not be the only option. You could also create your own result source to achieve the same results. Especially when there are several locations where you want to show a set of results that would be the solution. When configuring it for one place only the web part is a quick way to do so. When tweaking a query is really easy from within the Query Builder. Something that comes in handy when testing on how to exclude certain users from the results.