PowerShell Script For Deleting Note Board Web Part Post

In this article, we will go through the PowerShell script for deleting the post added from NoteBoard Web Part.

Background

On the Welcome page of one of the sites, we have added the NoteBoard Web Part as in the following:


But we encountered an issue in one of our environments. The user tried to delete his/her post, but wasn't able to do so. Instead, he got the following exception: "There was an error processing this request. Please refresh this page" as shown in the following screenshot.



For this, the PowerShell script is here with us. We are using the SocialDataService web service hosted in _vti_bin (http://<yoursitecollection>/_vti_bin/SocialDataService.asmx), that contains DeleteComment() as in the following:



Procedure

  1. Get the reference to the web service proxy, using the default credentials as in the following:
    1. $uri = URL of the web service http://<yoursitecollection>/_vti_bin/SocialDataService.asmx  
    2. $socialService = New-WebServiceProxy -Uri $uri –UseDefaultCredential  
  2. Now, once we have a reference to the service proxy, we can use the DeleteComment() method, that takes two parameters.

          a. URL: URL of the page from which we need to delete the comments.

          b. LastModifiedTime: This is actually the time the comment was added.

  3. In PowerShell, we can get the date and time using the Get-Date command as:
    1. $lastModifiedTime = Get-Date –Date “2015-05-05 00:00:00”  
    The following are a few references for Get-Date.

    https://technet.microsoft.com/en-us/library/ee692801.aspx
    https://technet.microsoft.com/en-us/library/hh849887.aspx
    https://technet.microsoft.com/en-us/library/ff730960.aspx

  4. Finally, calling the DeleteComment() method.
    1. $socialService.DeleteComment(<URL>,$lastModifiedTime)  
    Thanks!

    As always, feedback, comments, and suggestions are most welcomed.


Similar Articles