加雷特,你真是个天才!这是我从您提供的链接中学到的代码:
#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()
将代码另存为 AddScope.ps1,然后从提升的 cmd 控制台运行它:
PowerShell Set-ExecutionPolicy Unrestricted -force
PowerShell D:\Unattend\UserFiles\AddScope.ps1
而已!