How to read the response details from the discussion board list using Powershell script?

Requirement 

I have a SharePoint 2010 Discussion Board and it has many Discussions and Responses.

Customer asked me to read the responses entered for a particular discussion topic from the discussion board using Powershell script.

Solution

I have used the below Powershell script to do this.

cls
if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$web = Get-SPWeb “http://server/sites/JRDW”
$listName = $web.GetList(“http://server/sites/JRDW/Lists/TestDiscuss/”)
#Get desired discussion topic by Name Or Run a for each by removing the where class
$discussionTopics = $listName.Folders | Where-Object {$_.Name -eq “Test 1″}

#Get all discussion messages
$caml='<Where><Eq><FieldRef Name=”ParentFolderId” /><Value Type=”Integer”>{0}</Value></Eq></Where>’ -f $discussionTopics.ID
$query = new-object Microsoft.SharePoint.SPQuery
$query.Query = $caml
$query.ViewAttributes = “Scope=’Recursive'”;
$sourceMessages = $listName.GetItems($query)

foreach ($sourceMessage in $sourceMessages) {

Write-Host $sourceMessage[“Body”];
Write-Host $sourceMessage[“TrimmedBody”];
Write-Host $sourceMessage[“Author”];
Write-Host $sourceMessage[“Editor”];
Write-Host $sourceMessage[“Modified”];
Write-Host $sourceMessage[“Created”];

}

Advertisements

About Joseph Velliah
As a SharePoint Developer my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

Comments are closed.

%d bloggers like this: