Answered by:
create a sharepoint webpart page using Powershell

Question
-
I have to create a sharepoint webpart page using Powershell scripts.
Is there any way to do that ?
Tuesday, November 22, 2011 10:50 AM
Answers
-
Hi,
You achieve with powershell below:
$spWeb = Get-SPWeb -Identity "your site url"
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
# Create blank web part page
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" } #you may change "BlankWebPartPage.aspx" to your custom page layout file name
$newPage = $pubWeb.AddPublishingPage("your file name.aspx", $pl) #filename need end with .aspx extension
$newPage.Update()
# Check-in and publish page
$newPage.CheckIn("")
$newPage.ListItem.File.Publish("")
$spWeb.Dispose()Hope helps.
Cheers
- Marked as answer by star.warsModerator Wednesday, November 30, 2011 11:39 AM
Tuesday, November 22, 2011 1:46 PM -
for the line
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" } #you may change "BlankWebPartPage.aspx" to your custom
Change to your own page layout :)
- Proposed as answer by Rashu,Rahul Monday, November 28, 2011 3:52 AM
- Marked as answer by star.warsModerator Wednesday, November 30, 2011 11:40 AM
Tuesday, November 22, 2011 10:36 PM
All replies
-
Hi,
You achieve with powershell below:
$spWeb = Get-SPWeb -Identity "your site url"
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
# Create blank web part page
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" } #you may change "BlankWebPartPage.aspx" to your custom page layout file name
$newPage = $pubWeb.AddPublishingPage("your file name.aspx", $pl) #filename need end with .aspx extension
$newPage.Update()
# Check-in and publish page
$newPage.CheckIn("")
$newPage.ListItem.File.Publish("")
$spWeb.Dispose()Hope helps.
Cheers
- Marked as answer by star.warsModerator Wednesday, November 30, 2011 11:39 AM
Tuesday, November 22, 2011 1:46 PM -
hi,
Thanks for reply, 1 more thing
I have to use a Layout Template for that WebPart Page from the SharePoint specified layout templates.
I have to use "Left column, Header, Footer, Top Row, 3 columns" layout template, where can i specify to use that template.
- Edited by abhinav.s Tuesday, November 22, 2011 2:06 PM
Tuesday, November 22, 2011 2:06 PM -
for the line
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" } #you may change "BlankWebPartPage.aspx" to your custom
Change to your own page layout :)
- Proposed as answer by Rashu,Rahul Monday, November 28, 2011 3:52 AM
- Marked as answer by star.warsModerator Wednesday, November 30, 2011 11:40 AM
Tuesday, November 22, 2011 10:36 PM -
Hi cchitsiang,
Any Ideas about how can we create an aspx page / blank webpart page from powershell for sharepoint foundation 2010,
since sharepoiunt foundation 2010 won't be having the publishing feature and the microsoft.sharepoint.publishing dll. Your above code does not run in powershell if i am working in foundation 2010. So, How would you achieve this task ?
I am a newbie to 2010 so, please any help would be really needful ??
Thanks!!!!!!!!
- Edited by subhash_ss Thursday, May 17, 2012 6:32 AM
Thursday, May 17, 2012 5:54 AM -
Hi,
we had a similar problem and didn't want to use the publishing feature.
What worked surprisingly well for creating empty WebPartPages in the folder “SitePages” was something like this:
Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue;
$url = "http://myserver/site";
$listname = "SitePages"
$web = Get-SPWeb $url
$pagesLibrary = $web.Lists | Where { $_.Title -eq "SitePages" }
$pageLayout = 8
$cmd = '<?xml version="1.0" encoding="UTF-8"?><Method ID="0,NewWebPage"><SetList Scope="Request">' + $pagesLibrary.ID + '</SetList><SetVar Name="Cmd">NewWebPage</SetVar><SetVar Name="ID">New</SetVar><SetVar Name="Type">WebPartPage</SetVar><SetVar Name="WebPartPageTemplate">' + $pageLayout + '</SetVar><SetVar Name="Overwrite">true</SetVar><SetVar Name="Title">MyPage</SetVar></Method>';
$web.ProcessBatchData($cmd)
You can choose to create any other Page by changing the cmd Option like described in this MSDN article:
http://msdn.microsoft.com/en-us/library/ms450826.aspx
Wednesday, November 14, 2012 10:19 AM -
Hi,
I tried your variant with ProcessBatchData() but no luck - it gives me the following exception:
<Result ID="0,NewWebPage" Code="-2130575322">
<ErrorText>Указанный здесь список больше не существует.</ErrorText></Result>What I'm doing wrong? I do have the Site Pages available at http://ctc-vm-intranet:7777/SitePages/Forms/AllPages.aspx
Wednesday, March 26, 2014 12:46 PM -
Hi guys, please look into this script for future, it allows the automation of the whole lot, including creating the pages with custom txt and then adding the web-parts appropriately, you can also use it to add new webparts to existing pages and so on, Zones are also under your control, hope it helps thanks.
Monday, August 4, 2014 3:02 AM -
Hi JavaedAsgher,
where is the script ..? and opned the link (http://spsiteinstaller.codeplex.com ) there is no scripts, could you please help with script for create webpart page and add webparts(links, calendar, shared documents etc..)
kmk
Thursday, September 6, 2018 6:10 AM -
I can see that it is in archive now, since we haven't updated it for a while. It works on SP 2013 as well, I will have a dig around for the original source and re-upload it for you. Might take a day or so, thanks.Thursday, September 6, 2018 6:34 AM
-
Hi Javedasghar,
thanks for reply, if you found could you please share with me kmurali.krishna00@gmail.com
thanks.
kmk
Thursday, September 6, 2018 9:36 AM