使用Powershell导出快速搜索范围

时间:2014-05-16 14:18:08

标签: powershell sharepoint-2010 fastsearch

我想检索在一个环境中创建的快速搜索范围,并在新环境中恢复它们。有人试过吗?

1 个答案:

答案 0 :(得分:0)

我有这个让你入门......

首先,你必须导出范围,然后是范围规则:

# Search Service Application Name
$searchAppName = 'Search Service Application'

# Get Search Service Application
$searchApp = Get-SPEnterpriseSearchServiceApplication $searchAppName

# Get the Scopes
$scopes = Get-SPEnterpriseSearchQueryScope -SearchApplication $searchApp

# Export scopes to CSV
$scopes | Export-Csv -Path Scopes.csv

# Get the Scope Rules
$scopeRules = $scopes | Get-SPEnterpriseSearchQueryScopeRule

# Export scope rules to XML
$scopeRules | Export-Clixml -Path ScopeRules.xml

现在导入范围:

# Search Service Application Name
$searchAppName = 'Search Service Application'

# Get Search Service Application
$searchApp = Get-SPEnterpriseSearchServiceApplication $searchAppName

# Get .CSV file with Search Scope information
$File = 'Scopes.csv'

# Loop through the CSV file entries
$csvData = Import-Csv $File | ForEach-Object {
    Write-Host Creating Search Scope... $_.Name
    # Create New Search Scope
    $new = New-SPEnterpriseSearchQueryScope -SearchApplication $searchApp -Name $_.Name -Description $_.Description -DisplayInAdminUI ([System.Convert]::ToBoolean($_.DisplayInAdminUI))
}

对于搜索范围,我不确定这是否有效,您可能必须一次导入一个范围,并指定规则适用的范围。

# Get .XML file with Search Scope Rule information
$File = 'ScopeRules.xml'

#Import XML
$scopeRules = Import-Clixml $File

# Create New Search Scope Rule??
$scopeRules | New-SPEnterpriseSearchQueryScopeRule 

然后您可以启动范围更新编译

# Start Scope Update Compilation to add the new rules
Write-Host Start Scope Update Compilation...
$searchApp.StartScopesCompilation()