Proven way to hide disable or inactive users from SharePoint online search

SharePoint Online search: Proven way to hide disable or inactive users from SharePoint Online search – O365

No comments

Loading

Want to hide disable or inactive users from SharePoint online search? Sometimes we may need to hide the disabled or inactive users from the SharePoint online search, then how to handle this? In this article, I will explain how to implement this.

Description: Hide disable or inactive users from SharePoint online search

When some users already have left the origination, but those users continue to appear in the SharePoint search result in this scenario we have to hide the disabled inactive users from the below SharePoint online search page, what is the approach to implementing this?

1. https://sp.sharepoint.com/search/Pages/peopleresults.aspx

2. https://sp.sharepoint.com/sites/sales/_layouts/15/search.aspx

Resolution: Hide disable or inactive users from SharePoint online search

We need to follow the below steps to hide the inactive users from SharePoint Online search result

Step 1:

Get all disabled users from your local AD using the below PowerShell command and export to CSV.

Get-ADUser -Filter {Enabled -eq $false} | FT samAccountName, GivenName, Surname

Or

Get-ADUser -Filter {Enabled -eq $false} | select SamAccountName, GivenName, Department, Location | Export-Csv "C:\temp\ADDisabledUsers.csv"

Step 2:

Need to change the profiles AD property “msExchHideFromAddressLists” to True or Yes for all disabled users got in step 1

set-adobject -Identity $someoneDisabledUser -replace @{msexchhidefromaddresslists="$true"}

 

Notes:

The best way to update in bulk if we have more disabled users is as below:

  1. Export to CSV all disabled users using the above step 1 command.
  2. Read the csv – and inside foreach loop call the set-adobject -Identity $someoneDisabledUser -replace @{msexchhidefromaddresslists=”$true”}

Example:


$disabledUsersCSV=Import-Csv "C:\temp\ADDisabledUsers.csv"

foreach($oneDisabledUser in $disabledUsersCSV)
{
$disabledUser=$oneDisabledUser.SamAccountName
set-adobject -Identity $disabledUser -replace @{msexchhidefromaddresslists="$true"}   
}

 

Step 3:

Update the search query as below on the SharePoint search query page:

  1. Go to the enterprise search people results on page: https:///search/Pages/peopleresults.aspx Example: https://globalsharepoint.sharepoint.com/search/Pages/peopleresults.aspx
  2. Edit Search Results page
  3. Edit the People Results Web Part
  4. Change query
  5. Change Query Text from {searchboxquery} to {searchboxquery} AND -“SPS-HideFromAddressLists”:1

Outcome:

All disabled users will not be shown in the search.

Notes:

  • Changing the “MailNickName” attribute in on-premise AD is a must, without this attribute change the “msExchHideFromAddressLists” attribute will not be synced to SharePoint online.
  • This technique will not work – if the users are created in the cloud.
  • So Microsoft needs to change the below “May” to “Must” in the below document:

“Hint: You may (should be a must) need to add/update the “MailNickName” attribute in on-prem AD for the msExchHideFromAddressLists to sync. ”

Summary: Hide disable or inactive users from SharePoint online search

Thus, in this technique, we have learned about how to hide disabled or inactive users from SharePoint online search in office 365.

Reference URL: SharePoint online search

See Also: SharePoint Online PowerShell

You may also like the below SharePoint Online tutorials:

Buy SharePoint Online & Microsoft 365 Administration eBook

PDF Download Image

Download SharePoint Online & Office 365 Administration eBook

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:



Buy SharePoint Online & Office 365 Administration eBook


 

Get the free demo PDF eBook from here:

FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.

About Post Author

Do you have a better solution or question on this topic? Please leave a comment