如何使用PowerShell重建Windows搜索索引? [英] How to rebuild Windows Search Index by using PowerShell?

查看:53
本文介绍了如何使用PowerShell重建Windows搜索索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们没有找到针对不断增长的Windows Search数据库的解决方案(甚至没有Microsoft的帮助),我们决定在SCOM达到特定限制时定期重建数据库.这与Windows Server 2012 R2有关.

为此,我需要一个调用的PowerShell脚本.重置重新索引方法属于 ISearchCatalogManager 接口.

到目前为止,我提出了以下建议:

 #加载包含类&的DLL.介面添加类型路径"C:\ Temp \ SearchIndex \ Microsoft.Search.Interop.dll"#创建新的ISearchManager对象$ sm =新对象Microsoft.Search.Interop.ISearchManager#应该返回ISearchCatalogManager对象$ catalog = $ sm.GetCatalog("SystemIndex")#调用方法$ catalog.Reindex() 

这将引发以下异常:

 新对象:找不到构造函数.找不到适合于Microsoft.Search.Interop.ISearchManager类型的构造函数.在C:\ Users \ myuser \ Desktop \ test.ps1:8 char:6+ $ sm =新对象Microsoft.Search.Interop.ISearchManager+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~〜+ CategoryInfo:ObjectNotFound:(:) [New-Object],PSArgumentException+ FullyQualifiedErrorId:CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand 

我在做什么错了?

解决方案

原来,我使用的是 Microsoft.Search.Interop.dll 的过时版本.

这是我解决的方法:

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

 #加载包含类&的DLL.介面添加类型路径"C:\ Temp \ SearchIndexSdk \ Microsoft.Search.Interop.dll"#提供控制Search服务的方法.这#界面管理影响搜索引擎的设置和对象#跨目录.##https://msdn.microsoft.com/zh-CN/library/bb231485(v=vs.85).aspx$ sm =新对象Microsoft.Search.Interop.CSearchManagerClass#按名称检索目录并创建一个新的ISearchCatalogManager该目录的#个对象.$ catalog = $ sm.GetCatalog("SystemIndex")#通过重建数据库来重置基础目录#并执行完整索引.##https://msdn.microsoft.com/zh-CN/library/bb266414(v=vs.85).aspx$ catalog.Reset() 

As we didn't find any solution to our ever growing Windows Search DBs (not even with Microsofts help) we decided to rebuild the DBs regularily by SCOM, when they hit a specific limit. This relates to Windows Server 2012 R2.

I therefor need a PowerShell script that calls the Reset or Reindex method belonging to the ISearchCatalogManager interface.

So far I came up with the following:

# 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()

This however throws the following exception:

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

What am I doing wrong here?

解决方案

I turned out that I was using an outdated version of Microsoft.Search.Interop.dll.

Here is how I solved it:

First download the Windows Search 3.x SDK from Microsoft. Ignore the part about the system requirements. The required DLL can also be used on 2012 R2 (and very likely on 8.1). Then use below PowerShell code to reset the Search Index.

# 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()

这篇关于如何使用PowerShell重建Windows搜索索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆