1
因为我们没有找到任何解决方案来发展我们不断增长的Windows搜索数据库(甚至没有微软的帮助),我们决定在SCOM定期重建数据库时,他们达到了一个特定的限制。这涉及到Windows Server 2012 R2。如何使用PowerShell重建Windows搜索索引?
我为此需要一个PowerShell脚本,该脚本调用属于ISearchCatalogManager接口的Reset或Reindex方法。
到目前为止,我想出了以下内容:
# Load DLL containing classes & interfaces
Add-Type -path "C:\Temp\SearchIndex\Microsoft.Search.Interop.dll"
# Create new ISearchManager object
$sm = New-Object Microsoft.Search.Interop.ISearchManager
# should return ISearchCatalogManager object
$catalog = $sm.GetCatalog("SystemIndex")
# Call the method
$catalog.Reindex()
然而,这会引发以下异常:
New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Search.Interop.ISearchManager.
At C:\Users\myuser\Desktop\test.ps1:8 char:6
+ $sm = New-Object Microsoft.Search.Interop.ISearchManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
我在做什么错在这里?
你正试图实例化一个接口。这在C#中“起作用”,因为它透明地将正确的CoClass魔法化,但不是在PowerShell中,在那里你得到你所要求的东西。程序集是否包含“SearchManagerClass”? –
感谢您澄清。程序集包含'CSearchManagerClass'(注意它的C infront),但如果我调用'GetCatalog()'它不包含方法'Reindex()'和'Rebuild()' – Matze