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

powershell, vbscript, windows-search

Solution

Garett, you are a genius! This is the code I learned from the links you provided:

#Code copied from "Powershell Tackles Windows Desktop Search" http://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/
#Microsoft.Search.Interop.dll is needed, download from http://www.microsoft.com/en-us/download/details.aspx?id=7388
#Load the dll
Add-Type -path "D:\Unattend\UserFiles\Tools\Microsoft.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
$crawlman.AddUserScopeRule("file:///D:\*",$true,$false,$null)
$crawlman.SaveAll()

Save the code as AddScope.ps1, and run it from a elevated cmd console:

PowerShell Set-ExecutionPolicy Unrestricted -force
PowerShell D:\Unattend\UserFiles\AddScope.ps1

That's it!

Problem

I'm trying to add a location (scope) to my Windows 8 Search Index programmatically, and after some googling, I found this code: ``` Set objISAdm = CreateObject("Microsoft.ISAdm") Set objCatalog = objISAdm. GetCatalogByName("MyCatatlog") Set objScope= objCatalog.AddScope("C:\myfiles",False) objScope.Alias = "MyCatalogScope" ``` Unfortunately, a `800A01AD` error prompts suggesting object `Microsoft.ISAdm` cannot be created; with some further digging, it seems the above code doesn't work with the newer version of Windows Search on Windows 8. Does anyone know how to do that using VB scripts or from command line, presumably something works under windows 7 will work on Windows 8 as well?

Original source