I had a requirement to get all the social comments from a news board web part for a specific page. Though this can be achieved using "Server Side Object Model," it is restricted for some of the companies to run their "SSOM" code on production environment. Thus, we came up with an idea of creating PowerShell script using CSOM to retrieve social comments using "Social Data Web Service".
Here you will be seeing how to get all the social comments in SharePoint 2013 using the PowerShell + CSOM for a specific page using "Social Data WebService" (SocialDataService.asmx)
The below code retrieves all the comments for the specified page URL and exports the resulting data to Excel.
Code Usage
- ##Create an empty System.Array object
- $PageNoteBoardComments = @()
-
- ## Web Service Reference - http://Site/_vti_bin/SocialDataService.asmx
- $uri="http://<sitepath>/_vti_bin/SocialDataService.asmx?wsdl"
-
- ##PageURL to be specified as input parameter of which contains social comments.
- $url="http://<sitepath>/Pages/TopNews.aspx"
-
- ## if you are executing this code in a Virtual Machine it's default credentials will be used to connect to proxy.
- $socialDataServiceWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
-
- ##Get total number of comments for a specified URL
- [int]$CountCommentsOnUrl=$socialDataServiceWebServiceReference.CountCommentsOnUrl($url)
-
- Write-Host -ForegroundColor Green "Number of comments for the specified URL : " $CountCommentsOnUrl
-
- ##Get Comments for the URL Specified
- $CommentsOnUrl = $socialDataServiceWebServiceReference.GetCommentsOnUrl($url,$null,$null,$null)
-
- ##Iterate on the comments collection and store the value in PageNoteBoardComments array object.
- foreach($item in $CommentsOnUrl)
- {
-
- $PageNoteBoardComments += New-Object
- PsObject -property @{
-
- 'Comments' = $item.Comment
-
- 'Last Modified Time' = $item.LastModifiedTime
-
- 'URL' = [string]$item.Url
-
- 'Owner' = [string]$item.Owner
-
- 'Page Title' = [string]$item.Title
- }
- }
-
- ##Finally, use Export-Csv to export the data to a csv file
- $PageNoteBoardComments | Export-Csv -NoTypeInformation -Path "D:\Madhu\Powershell\NoteBoardComments.csv"
Scenario 2
To iterate all the page URL's from excel and to retrieve all the social comments from social data web service based on page URL.
Note
All the Page URL's are stored under "PageUrl" column in excel sheet.
Please feel free to share your comments.
I hope this helps!!!!!