【发布时间】:2017-01-24 21:59:22
【问题描述】:
由于我们没有为不断增长的 Windows Search 数据库找到任何解决方案(即使在 Microsoft 的帮助下也没有),我们决定在数据库达到特定限制时由 SCOM 定期重建这些数据库。这与 Windows Server 2012 R2 有关。
因此我需要一个 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),但如果我随后调用GetCatalog(),它不包含方法Reindex()或Rebuild()
标签: c# windows powershell