Get all the Social Tags for the specified URL in SharePoint 2010 using powershell


Social Tag can be created for any specified URL with a valid term using SocialTagManager object. SocialTagManager object contains methods and properties that are used to manipulate social tag data. Here we will be seeing how to get all the social tags for the specified URL in SharePoint 2010 using Powershell.

View all the social tags for the specified URL through Central Administration:

  1. Open Central Administration by going Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Central Administration.
  2. Click on Manage Service Application which is available in Application Management section.

    SharePoint 2010

    Figure : Application Management section in SharePoint 2010
  3. Click on User Profile Service Application.
  4. Click on Manage Social Tags and Notes which is available in "My Site Settings" section.

    SharePoint with powershell
  5. Select Tags from the Type dropdown and enter the URL.
  6. Click on Find.
  7. You could be able to see the Social Tags for the specified URL.

Automation: Get all the Social Tags in SharePoint 2010 using PowerShell

Steps Involved:

  1. Create the input xml file which contains the inputs for getting all the social tags.
  2. Create ps1 file which contains the script for getting all the social tags.

CreateSocialTag.xml

<?xml version="1.0" encoding="utf-8" ?>
<SocialTag>
  <
SiteURL> https://serverName.com/Finance/Finance/</SiteURL>
  <Uri>https://serverName.com/Finance/Finance/</Uri
</SocialTag>

CreateSocialTag.ps1

## -------------------------------------------------------------------
## Powershell script for retrieving Social Tag for the specified URL
## 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\RetrieveSocialTag.xml"    
 
#----------------Retrieve Social Tag function----------------------------------------------------                 
     
function RetrieveSocialTag()
      {          
            
$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 -TypeName Microsoft.Office.Server.SocialData.SocialTagManager -ArgumentList $context
                 
                
##GetTags(Uri) method is used to retrieve an array of SocialTag objects that are owned by the current user and that contain the specified URL.
                [Microsoft.Office.Server.SocialData.SocialTag[]]$tags = $socialTagManager.GetTags($uri)                 
                
Write-Host -ForegroundColor Green "Tags for the URL: " $uri.AbsoluteUri
                 
                
foreach ($tag in $tags)
                {
                   
Write-Host -ForegroundColor Magenta "###############################################"
                    Write-Host -ForegroundColor Yellow " Tag Name : " $tag.Term.Name
                    
Write-Host -ForegroundColor Yellow " URL      : " $tag.Url.AbsoluteUri
                   
Write-Host -ForegroundColor Yellow " Title    : " $tag.Title
                   
Write-Host -ForegroundColor Yellow " Owner    : " $tag.Owner.DisplayNam                 
                }          
                 
## Dispose the site object
                  $site.Dispose()
         }

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

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 the D:\VijaiPOC\RetrieveSocialTag.ps1

Thus in this article we have seen how to get all the social tags using powershell in SharePoint 2010.