Showing posts with label New-SPEnterpriseSearchMetadataCrawledProperty. Show all posts
Showing posts with label New-SPEnterpriseSearchMetadataCrawledProperty. Show all posts

Sunday, February 22, 2015

Create Crawled Property for Custom Column - SharePoint 2013

Create Site column "TestName" using following powershell script 
#Get site and web object
$site = Get-SPSite -Identity "http://MySiteurl"
$web = $site.RootWeb
#Assign fieldXML variable with XML string for site column
$fieldXML = '<Field Type="Text"
Description="This is a test date column."
DisplayName="Test Name"
Group="Test Custom Columns"
#Output XML to console
write-host $fieldXML
#Create site column from XML string
#Example of changing the site column settings after creation
#Configure Test Date column to be Date Only instead of Date & Time
$dtField = $web.Fields["Test Name"]
#Dispose of Web and Site objects
Open  Search Service application  in central admin and run incremental crawl. 
Under Crawled properties search for "TestName"
If missing custom site columns in crawled properties, you should:
  1. verify your custom fields is in use (in existing item or at least associated with visible content type)
  2. check your search settings and crawled category properties
  3. do a Search Index Reset
  4. perform a full crawl
Even after full crawl if you can't find your column in crawled properties then create it using following powershell script.

add-pssnapin microsoft.sharepoint.powershell

$searchapp = Get-SPEnterpriseSearchServiceApplication

$cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $searchapp -Identity SharePoint

$crawlprop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Limit 1

New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Name "ows_TestName" -PropSet $crawlprop.PropSet -Category $crawlprop.CategoryName -IsNameEnum $false -VariantType $crawlprop.VariantType -IsMappedToContents $false

Now search again in crawled properties. you will find your "TestName" column.