top of page

Create Social Tag in SharePoint 2010 using PowerShell

Automation: Create a Social Tag in SharePoint 2010 using PowerShell

A Social Tag can be created for any specified URL with a valid term using the  SocialTagManager object. SocialTagManager object contains methods and properties that are used to manipulate social tag data.

Steps Involved:

  1. Create the input xml file which contains the inputs for creating social tag.

  2. Create a ps1 file which contains the script for creating social tag.


<?xml version="1.0" encoding="utf-8" ?> <SocialTag>   <SiteURL></SiteURL>   <Uri></Uri>   <TermName>Sample Tag</TermName > </SocialTag>


## ------------------------------------------------------------------- ## Powershell script for creating Social Tag ## Note     : Need to update the XML file path before running the script. ## Author   : Vijai Anand Ramalingam ## Date     : 28-Oct-2011 ## ------------------------------------------------------------------- #----------------Get the xml file--------------------------------------------------------------- [xml]$xmlData=Get-Content "D:\VijaiPOC\CreateSocialTag.xml"

#----------------Create Social Tag function---------------------------------------------------- function CreateSocialTag()       {           $uri = New-Object System.Uri($xmlData.SocialTag.Uri); $site = Get-SPSite $xmlData.SocialTag.SiteURL            ## Get the context of the service application $context = Get-SPServiceContext($site)  ## SocialTagManager - Contains methods and properties used to manipulate social tag data $socialTagManager = New-Object -TypeNameMicrosoft.Office.Server.SocialData.SocialTagManager -ArgumentList $context ## Retrieve the taxonomy session from the SocialTagManager. $taxSession = $socialTagManager.TaxonomySession $termStore = $taxSession.DefaultKeywordsTermStore

$term = $termStore.KeywordsTermSet.CreateTerm($xmlData.SocialTag.TermName,$termStore.DefaultLanguage) $termStore.CommitAll()  ## Creates a SocialTag object with the specified Uri, Term, String and Boolean. ## $term - Term object ## $site.RootWeb.Title - Title of the web page whose URL is being tagged ## $true - A Boolean value indicating whether the social tag is private. If it is not private, the tag will be visible to users other than the owner.

$socialTagManager.AddTag($uri, $term, $site.RootWeb.Title,$true);                    ## Dispose the site object $site.Dispose()     }

#----------------Calling the function------------------------------------------------------------

CreateSocialTag Run the Script:

  1. Go to Start.

  2. Click on All Programs.

  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell (run as Administrator).

  4. Run theD:\VijaiPOC\CreateSocialTag.ps1

Newly created social tag:

  • Open Central Administration by going Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Central Administration.

  • Click on Manage Service Application which is available in Application Management section.

Figure : Application Management section in SharePoint 2010

  • Click on User Profile Service Application.

  • Click on Manage Social Tags and Notes which is available in "My Site Settings" section.

  • Select Tags from the Type dropdown and enter the URL and Tag/Note contains value.

  • Click on Find.

  • You could be able to see the Social Tag that we have created using Powershell.

Thus in this article we have seen how to create social tag using powershell in SharePoint 2010.



bottom of page