How to “Enable this Library as a Catalog” in SharePoint 2013 using PowerShell

Sathish Nadarajan
 
Solution Architect
February 11, 2015
 
Rate this article
 
Views
10659

Probably we would have fed up with reading and doing the things using PowerShell for the last few days. But anyhow, nowadays, I involved much into these stuffs. Basically the reason behind this is, to eliminate the steps from the Release Notes. That is, the Technical Team from the customer’s end can run the Scripts alone, instead of doing the steps manually through the User Interface. Though these things are going to be a one-time activity, these things will add some value to our customer.

In this article, let us see, how to enable a Library as a Catalog. As usual, let us see how to do this through the Interface. Then we will see the PowerShell Script

1. On the Pages – Settings

image

2. Click on the “Catalog Settings”

image

3. Select the Check Box

4. Enable the Anonymous access

5. Frame the URL with the fields

6. Select the Navigation Hierarchy.

All these steps can be done using the script.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".EnableCatalogConnection-$LogTime.rtf"
 
 
 cls
 
 
 ##================================================================================================
 ## Description	: Enable Catalog Connection
 ## Author		: Sathish Nadarajan
 ## Date			: 09-Dec-2014
 ##================================================================================================
 
 
  
 $Host.UI.RawUI.WindowTitle = "-- Enable Catalog Connection  --"
 
 $StartDate = Get-Date
 Write-Host -ForegroundColor White "------------------------------------"
 Write-Host -ForegroundColor White "| Enable Catalog Connection  |"
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 Write-Host -ForegroundColor White "------------------------------------"
 
 
 
 #start-transcript $LogFile
 
 ################################################### Add SharePoint PowerShell Snapin   ######################################
 
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
     Add-PSSnapin Microsoft.SharePoint.Powershell
 }
 
 
 ########################################################### End of PowerShell Snapin ########################################
 
 ########################################################### Set the Exxecution Path #########################################
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
  
 ########################################################### Function Declarations ########################################
 
 
 function SetListAsCatalog([string] $siteUrl, [string] $webUrl,[string] $listDisplayName,[string] $termStoreName,[string] $termGroupName,[string] $termSetName,[string] $fieldInternalName)
 {
     Write-Host -ForegroundColor Yellow "Going to Enable Search Catalog On the List - " $listDisplayName
 
     $site = get-SPSite -Identity $siteUrl
 
     $parentWeb = Get-SPWeb -Site $site -Identity $webUrl
 
     $parentWeb.AnonymousState = "Enabled"
 
     #web.AnonymousPermMask64 = SPBasePermissions.Open | SPBasePermissions.ViewPages;    
     $parentWeb.Update()
 
     $list = $parentWeb.Lists[$listDisplayName];
  
     # get managed metadata info for populating details about Catalog Navigation
  
     $taxSession = New-Object -TypeName Microsoft.SharePoint.Taxonomy.TaxonomySession @($parentWeb.Site);
  
     $termStore = $taxSession.TermStores[$termStoreName];
  
     $group = $termStore.Groups[$termGroupName];
  
     $termSet = $group.TermSets[$termSetName];
  
     # set up CatalogTaxonomyFieldSettings for the single value tagging field DemoTag1
  
     $taxFieldSetting = New-Object -TypeName Microsoft.SharePoint.Publishing.CatalogTaxonomyFieldSettings;
  
     $field = $list.Fields.getfieldbyinternalname($fieldInternalName);
  
     $taxFieldSetting.TermId = $field.AnchorId;
  
     $taxFieldSetting.TermSetId = $termSet.Id;
  
     $taxFieldSetting.TermStoreId = $termStore.Id;
  
     $taxFieldSetting.FieldId = $field.Id;
  
     $taxFieldSetting.FieldManagedPropertyName = "owstaxid" + $field.InternalName;
  
     $taxFieldSetting.IsSelected = $True;
  
     $taxFieldSetting.FieldDisplayName = $field.StaticName;
  
     # there can be more than one single value tagging field to integrate on when connecting, so the parameter expects an IEnumerable
  
     $taxFieldSettings = New-Object -TypeName System.Collections.Generic.List[Microsoft.SharePoint.Publishing.CatalogTaxonomyFieldSettings];
  
     $taxFieldSettings.Add($taxFieldSetting);
  
     # specify the Primary Key or FURL fields default as just /[Title]
  
     $selectedIds = New-Object -TypeName System.Collections.Generic.List[System.String];
  
     #$selectedIds.Add("Question");    ################## Commented this line as such this is not applying properly.
 
  
     # publish the list as a catalog
  
     [Microsoft.SharePoint.Publishing.PublishingCatalogUtility]::PublishCatalog($parentWeb, $list, $False, $selectedIds, $taxFieldSettings);
 
     if($list.AnonymousPermMask -ne $null)
     {
         $list.AnonymousPermMask = 8192
     }
 
     $versionObj = $list.RootFolder.Properties["vti_searchversion"]
     $list.RootFolder.SetProperty("vti_searchversion", ($versionObj + 1));  
     $list.Update()
 
     Write-Host -ForegroundColor Green "Search Catalog Enabled Successfully On the List - " $listDisplayName
 }
 
 
 ########################################################### End of Function Declarations ########################################
 
 ###################### Calling Functions###################################################
 
 $EnableCatalogDetailsCSV = $scriptBase + "" + "02.CatalogDetails.csv"
 
 
 import-csv $EnableCatalogDetailsCSV | where {
     
     
     SetListAsCatalog $_.siteUrl $_.webUrl $_.listDisplayName $_.termStoreName $_.termGroupName $_.termSetName $_.fieldInternalName
 
 
 }
 
 
 
 
 
 ###################### End of Calling Functions###################################################
 
 #stop-transcript 
 

DOWNLOAD HERE

 

 

Happy Coding.

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment