Remove and Create Managed Property, Index reset
#input parameter
$searchAppName="Enterprise Search Service Application"
#Search Index Reset
#Get the search service application
#You will need to specify the -Identity switch and a name if you have more than one
$searchapp = Get-SPEnterpriseSearchServiceApplication $searchAppName
#Reset index with the following options in brackets:
#Disable Alerts $true/$false
#Ignore unreachable server $true/$false
try
{
Write-Host "Attempting to reset the index...please wait"
$searchapp.Reset($false, $false)
Write-Host "Index successfully reset"
}
catch
{
Write-Host "There was a problem resetting the index:" $_ -ForegroundColor Red
}
function CreateManagedProperty
{
param(
[String]$searchAppName,
[String]$managedPropertyName,
[String]$crawledPropertyName
)
#set default value for search application
if($searchAppName -eq $null -or $searchAppName -eq '')
{
$searchAppName = 'Enterprise Search Service Application'
}
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin=Get-PSSnapin | Where-Object {
$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$searchapp = Get-SPEnterpriseSearchServiceApplication $searchAppName
#$category = Get-SPEnterpriseSearchMetadataCategory –Identity SharePoint -SearchApplication $searchapp
$category="Sharepoint"
$crawledproperty = New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType 31 -PropSet "00130329-0000-0130-c000-000000131346" -Name $crawledPropertyName -IsNameEnum $false
$managedproperty=Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $managedPropertyName -ea 0
if($managedproperty -ne $null) #if managed property exists, remove it
{
$managedproperty.DeleteAllMappings()
$managedproperty.Delete()
}
#managed property doesn't exist, create
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $managedPropertyName -Type 1 -EnabledForScoping 1
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty
} #end function
#============================================ calling function ===================
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "categorycard" -crawledpropertyName "ows_AvanadeGBPTaxonomy"
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "categorytags" -crawledpropertyName "ows_Avanade_x002d_GBP_x002d_CategoryCardTags"
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "faqtopic" -crawledpropertyName "ows_GBPFaqTopic"
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "faqquestion" -crawledpropertyName "ows_GBPFaqQuestion"
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "faqbusinessunit" -crawledpropertyName "ows_GBPusinessUnit"
CreateManagedProperty -searchAppName $searchAppName -managedPropertyName "pagelanguage" -crawledpropertyName "ows_Avanade_x002d_GBP_x002d_PageLanguage"