Friday, August 9, 2013

Add List Item to SharePoint Discussion board using PowerShell

Discussion board is a predefined list template which is used to store the discussions and replies as List Items. But these discussion list Items are slightly varies from the normal list Item, were every top level Discussion Items are treated as Folder and all the replies are stored under those folder.  

Below is the code snippet to create a discussion item in Discussion board.

$site=Get-SPSite http://site/
if($list -ne $null)
$newTopic = [Microsoft.SharePoint.Utilities.SPUtility]::CreateNewDiscussion($list, "Service Request");
$newTopic["Body"] = "Test";
$newTopic["Subject"] = "Service Request";
$newTopic["ColumnName"] = "Value";
Write-Host -ForegroundColor Green $newTopic.Title " discussion topic is created successfully"
Write-Host -ForegroundColor Yellow "List does not exists."

Related Posts Plugin for WordPress, Blogger...