SharePoint 2010: PowerShell Script to add / display list as webpart

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: