首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用PowerShell重建Windows Search索引?

如何使用PowerShell重建Windows Search索引?
EN

Stack Overflow用户
提问于 2016-09-16 23:44:26
回答 1查看 7.2K关注 0票数 3

由于我们没有为不断增长的Windows搜索数据库找到任何解决方案(甚至在微软的帮助下也没有),所以当数据库达到特定限制时,我们决定通过SCOM定期重建数据库。这与Windows Server 2012 R2相关。

因此,我需要一个PowerShell脚本来调用属于ISearchCatalogManager接口的ResetReindex方法。

到目前为止,我想出了以下几点:

代码语言:javascript
运行
复制
# 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()

但是,这会抛出以下异常:

代码语言:javascript
运行
复制
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

我在这里做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-19 21:21:20

我发现我使用的是一个过时的Microsoft.Search.Interop.dll版本。

下面是我解决这个问题的方法:

首先从微软下载Windows Search 3.x SDK。忽略有关系统要求的部分。所需的DLL也可以在2012 R2上使用(很可能在8.1上)。然后使用下面的PowerShell代码重置搜索索引。

代码语言:javascript
运行
复制
# Load DLL containing classes & interfaces
Add-Type -path "C:\Temp\SearchIndexSdk\Microsoft.Search.Interop.dll"

# Provides methods for controlling the Search service. This 
# interface manages settings and objects that affect the search engine 
# across catalogs. 
#
# https://msdn.microsoft.com/en-us/library/bb231485(v=vs.85).aspx
$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. 
#
# https://msdn.microsoft.com/en-us/library/bb266414(v=vs.85).aspx
$catalog.Reset()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39535442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档