Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We are creating a powershell script to create lists, groups and to install wsp packages.

There are 5 wsp each containing 1 webpart. Is there any way via powershell to create 1 site page and embed 1 webpart on each page?

We have to create new sites pages for every deployment/testing, so feel that it would save lot of time if this was possible via powershell.

I am following link1 and link2 but looks like they are referring to publishing pages, I want to make webpart pages..

share|improve this question
    
Do you want a yes or no answer? If so: Yes ;) –  Robert Lindgren Feb 27 at 11:02
    
Hi, I am looking for code for webpart page and them to embed webpart on it. We have worked with publishing pages. But not with webpart pages –  variable Feb 27 at 11:44
add comment

1 Answer

Here is the PowerShell code to create a webpart page:

Add-PsSnapin Microsoft.SharePoint.PowerShell 

$pageTitle = "Page Name"
$layoutTemplate = 4  # Template code
$web = Get-SPWeb http://server/site  
$list = $web.GetList("http://server/site/LibraryName/")
$xml = "<?xml version=""1.0"" encoding=""UTF-8""?><Method ID=""0,NewWebPage""><SetList Scope=""Request"">" + $list.ID + "</SetList><SetVar Name=""Cmd"">NewWebPage</SetVar><SetVar Name=""ID"">New</SetVar><SetVar Name=""Type"">WebPartPage</SetVar><SetVar Name=""WebPartPageTemplate"">" + $layoutTemplate + "</SetVar><SetVar Name=""Overwrite"">true</SetVar><SetVar Name=""Title"">" + $pageTitle + "</SetVar></Method>"
$result = $web.ProcessBatchData($xml)
# Possible LayoutTemplate values:
# 1 - Full Page, Vertical
# 2 - Header, Footer, 3 Columns
# 3 - Header, Left Column, Body
# 4 - Header, Right Column, Body
# 5 - Header, Footer, 2 Columns, 4 Rows
# 6 - Header, Footer, 4 Columns, Top Row
# 7 - Left Column, Header, Footer, Top Row, 3 Columns
# 8 - Right Column, Header, Footer, Top Row, 3 Columns

Source:http://social.technet.microsoft.com/Forums/sharepoint/en-US/39c98f27-248c-40b7-b859-088c7dcdeedc/cannot-create-web-part-page-with-powershell?forum=sharepointadminprevious

You can then add the webpart to the webpart page by using the code prsent in one of the posts you mentioned in the question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.