Create Social Comments in SharePoint 2010 using PowerShell


In this article you will be seeing how to create Social Comments for any specified URL in SharePoint 2010 using Powershell.

Automation: Create Social Comments in SharePoint 2010 using PowerShell

Social Comments can be created for any specified URL. SocialCommentManager object is used to create Social Comment for any specified URL.

Steps Involved:

  1. Create the input xml file which contains the inputs for creating social comments.
  2. Create ps1 file which contains the script for creating social comments.

CreateSocialComment.xml

<?xml version="1.0" encoding="utf-8" ?>
<SocialComment>
  <
SiteURL> https://serverName.com/Finance/Finance/</SiteURL>
  <Uri>https://serverName.com/Finance/Finance/</Uri>
  <Comment>My Comment</Comment>
  <Title>Comments</Title>
</SocialComment>

CreateSocialComment.ps1

## -------------------------------------------------------------------
## Powershell script for creating Social Comment
## Note     : Need to update the XML file path before running the script.
## Author   : Vijai Anand Ramalingam
## Date     : 31-Oct-2011
## -------------------------------------------------------------------

#----------------Get the xml file---------------------------------------------------------------

[xml]$xmlData=Get-Content "D:\VijaiPOC\CreateSocialComment.xml"  

#----------------Create Social Comment function----------------------------------------------------

      function CreateSocialComment()
      {          
           
$uri = New-Object System.Uri($xmlData.SocialComment.Uri)
           
$site = Get-SPSite $xmlData.SocialComment.SiteURL
           
$comment = $xmlData.SocialComment.Comment
           
$title = $xmlData.SocialComment.Title 

            ## Get the context of the service application
            $context = Get-SPServiceContext($site)

            ## SocialCommentManager – used to create the Social Comment for any specified URL
            $socialCommentManager = New-Object -TypeName Microsoft.Office.Server.SocialData.SocialCommentManager -ArgumentList $context

            ## Methods used to add social comments
            ## AddComment(Uri, String) – used to add the social comment for the specified URL
            ## AddComment(Uri, String, Boolean) – used to add the social comment for the specified URL and gives the comment the specified priority
            ## AddComment(Uri, String, Boolean, String) – used to add the social comment for the specified URL and gives the comment the specified priority and title

            $socialCommentManager.AddComment($uri, $comment,$true $title); 

                  ## Dispose the site object
                  $site.Dispose()
    }

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

CreateSocialComment

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\CreateSocialComment.ps1

Newly created social comment:

  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.

    SclShare1.gif

    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.

    SclShare2.gif
     

  5. Select Notes from the Type dropdown and enter the URL and Tag/Note contains value.

  6. Click on Find.

  7. You could be able to see the Social Comment that we have created using Powershell.

    SclShare3.gif
     

  8. Alternate way: Navigate to the URL for which you have created the social comment.

  9. In the ribbon interface, click on Tags & Notes button.

  10. Click on Note Board tab and you could see the social comment that you have created as shown in the following figure.

    SclShare4.gif

Summary:

Thus in this article you have seen how to create social comments using powershell in SharePoint 2010.

Up Next
    Ebook Download
    View all
    Learn
    View all