Scenario:
We were required to add / display discussion forum / discussion board as a webpart on a publishing page.
Resolution:
We used “XsltListViewWebPart” webpart to accomplish above requirement
$webpart = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart
$webpart.ListId = $list.ID;
$webpart.ViewGuid = $list.DefaultView.ID.ToString();
$webpart.AllowClose = $false;
$webpart.AllowConnect = $false;
$webpart.AllowEdit = $false;
$webpart.AllowHide = $false;
$webpart.AllowMinimize = $false;
$webpart.AllowZoneChange = $false;
$webpart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::None;
$webpartmanager=$web.GetLimitedWebPartManager($pageUrl,
[System.Web.UI.WebControls.WebParts.PersonalizationScope]
::Shared)
$webpartmanager.AddWebPart($webpart, “Zone 1″, 0);
You need to set following variables:
$list = Get the reference of list. In our case, it was discussion forum
$pageUrl = Url of the page
