SharePoint Pals
 | Sign In
How to “Enable this Library as a Catalog” in SharePoint 2013 using PowerShell
by Sathish Nadarajan 11 Feb 2015
Author
SharePoint MVP
Visits   
Today  :   1     Total  :    6847

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.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart https://t.co/VxSi4QnNrC

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window https://t.co/EQ7HkoZDkX

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features https://t.co/zAXObHCFpH

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013 https://t.co/LEwnUoI7EY

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services https://t.co/Yvp2VPFIRP

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation