How to query and add (if not listed) a location to Windows 10 Search Index using PowerShell

  add, indexing, location, search, windows

I have to re-mount removable drives (which require authentication) each time I boot the computer and Windows Indexing keeps removing the removable drives (perhaps because the removable drives are not available when the computer boots). In an ideal world Windows Indexing would keep these locations and just list them as ‘Unavailable’ (which it sometimes does). However because it doesn’t I am interested in executing a script that queries the Windows Indexing locations and if it does not list the removable drives then add them. At the bottom of this thread I pasted the Batch script that I setup to run at boot (via Start Up folder) to search for a specific folder that is available thereafter mounting one of the removable drives.

I have found several examples of how to do this on Windows 7 (links pasted below) but I can’t figure out how to do it in Windows 10. The links provided to the DLL (Microsoft.Search.Interop.dll) no longer resolve.

When searching for the latest Windows Search SDK for Windows 10 I was lead to the Windows SDK here:
I installed the C++ related portion of the Windows SDK then searched for Microsoft.Search.Interop.dll but I couldn’t find it. Perhaps the DLL has changed?

From How to rebuild Windows Search Index by using PowerShell?

Load DLL containing classes & interfaces

Add-Type -path "C:TempSearchIndexSdkMicrosoft.Search.Interop.dll"

#Provides methods for controlling the Search service. This
interface manages settings and objects that affect the search engine
across catalogs.

$sm = New-Object Microsoft.Search.Interop.CSearchManagerClass

#Retrieves a catalog by name and creates a new ISearchCatalogManager
object for that catalog.

$catalog = $sm.GetCatalog("SystemIndex")

#Resets the underlying catalog by rebuilding the databases and performing a full indexing.



From How to add a location to windows 7/8 search index using batch or vbscript?

#Code copied from "Powershell Tackles Windows Desktop Search"
#Microsoft.Search.Interop.dll is needed, download from

#Load the dll

Add-Type -path "D:UnattendUserFilesToolsMicrosoft.Search.Interop.dll"

#Create an instance of CSearchManagerClass

$sm = New-Object Microsoft.Search.Interop.CSearchManagerClass

#Next we connect to the SystemIndex catalog

$catalog = $sm.GetCatalog("SystemIndex")

#Get the interface to the scope rule manager

$crawlman = $catalog.GetCrawlScopeManager()

#add scope



I would add a comment to the existing threads but I am not able to because I don’t have reputation of 50 (dumb rule IMO).

Last… I found this site which lists the DLL along with some code but it hasn’t been updated in a long time.

Thanks in advance!

Batch script that runs at boot:

@echo off

echo Windows Search is being restarted to recognize the Z drive


if EXIST Z:Watch (


sc stop WMPNetworkSvc

ping -n 5 > nul

sc stop WSearch

ping -n 5 > nul

sc start WSearch

ping -n 5 > nul

sc start WMPNetworkSvc

echo Exiting this script in 5 seconds

ping -n 5 > nul


) else (

echo Waiting 60 seconds to check if Z drive is available

ping -n 60 > nul

goto :while


Source: Windows Questions