This script file will create an Custom Entity Extraction dictionary file which is the specific XML format that can be uploaded with the Add-FastSearchResource cmdlet. This script is based on Keenan's cool one (http://gallery.technet.microsoft.com/scriptcenter/15f58a4a-42e5-44b8-b17e-624b83d6f902). Also, please check this linked information.
This script takes all of the unique values of TWO SharePoint list columns and outputs the key-value pairs to xml file that can be imported as a Custom Entity Extraction dictionary file.

How to use

  1. Save this script as 'createCPEDictionaryFromSPList.ps1'
  2. Create a SharePoint list which have at least 2 columns - one is for 'key', second is for 'value'
  3. Launch SharePoint shell as the specific user who have the permission to read from the SharePoint list
  4. Run 'createCPEDictionaryFromSPList.ps1' as the following format. After that you will see output.xml file which have all custom entity extraction informations
    • Note that if 5th parameter set $false, this script usually do NOT pick 'value' from the SharePoint List. 
Windows Shell Script
Edit|Remove
.\createCPEDictionaryFromSPList.ps1 "SharePoint Site (e.g. http://intranet.contoso.com/)" "SharePoint List name (e.g. Product)" "Column name for 'key' (e.g. Key)" "Column name for 'value' (e.g. Value)" $true "C:\temp\output.xml"

 Code Section

PowerShell
Edit|Remove
param([string]$siteUrl, [string]$listName, [string]$keyColumnName, [string]$valueColumnName, [bool]$valueFlag, [string]$output) 
 
Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue  
 
function createCPEDictionaryFromSPList ($url$listName$keyFieldName$valueFieldName$valueFlag$output){ 
    # Get list from specified Sharepoint web 
    $SPWeb = get-spweb $url 
 
    $uniqueKeyValue = new-object System.Collections.Specialized.NameValueCollection 
     
    if($listName -is [array]) { 
        foreach($name in $listName) 
        { 
            $reflist = $SPWeb.Lists.TryGetList($name) 
            $keyFName = $keyFieldName[$name] 
            $valueFName = $valueFieldName[$name] 
             
            foreach ($listItem in $reflist.Items) { 
                $keyFieldValue = $listItem[$keyFName] 
                $valueFieldValue = $listItem[$valueFName] 
 
                if($keyFieldValue) { 
                    if($valueFlag -and $valueFieldValue) { 
                      $uniqueKeyValue.add($keyFieldValue$valueFieldValue) 
                    } else { 
                      $uniqueKeyValue.add($keyFieldValue$keyFieldValue) 
                    } 
                } 
            } 
        } 
    } else { 
        $reflist = $SPWeb.Lists.TryGetList($listName) 
         
        foreach ($listItem in $reflist.Items) { 
            $keyFieldValue = $listItem[$keyFieldName] 
            $valueFieldValue = $listItem[$valueFieldName] 
             
            if($keyFieldValue) { 
                if($valueFlag -and $valueFieldValue) { 
                  $uniqueKeyValue.add($keyFieldValue$valueFieldValue) 
                } else { 
                  $uniqueKeyValue.add($keyFieldValue$keyFieldValue) 
                } 
            } 
        } 
    } 
     
    # Create XML with the root element 
    [XML]$outputXml = "<dictionary></dictionary>" 
    $root = $outputXml.get_DocumentElement() 
     
    # Add entry elements 
    foreach ($key in ($uniqueKeyValue.AllKeys | sort)) 
    { 
        $element = $outputXml.CreateElement("entry") 
        $element.SetAttribute("key"$key) 
        $element.SetAttribute("value"$uniqueKeyValue.GetValues($key)) 
        [void]$root.AppendChild($element) 
    } 
     
    $SPWeb.Dispose() 
     
    # Save the output XML file 
    $XmlWriter = New-Object System.Xml.XmlTextWriter($output, [System.Text.Encoding]::UTF8) 
    $xmlWriter.Formatting = [System.Xml.Formatting]::Indented 
    $outputXml.Save($XmlWriter) 
    $xmlWriter.Close() 
     
    return 
} 
 
createCPEDictionaryFromSPList $siteUrl $listName $keyColumnName $valueColumnName $valueFlag $output