Sunday, 14 February 2016

Create Publishing Page using Powershell/ Create Pages from csv file



Below is the code which will create the Publishing page and added to Pages library . Here i am using Blankwebpart page layout and reading pageurls from text file and creating pages.

cls
asnp "*sh*"
$web=Get-SPWeb -Identity http://SP2013dev:3636/
$pubweb=[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$file=Import-Csv -LiteralPath E:\MS\temp\pageurls.txt
$pageLayout=$pubweb.GetAvailablePageLayouts()|?{$_.Name -eq "BlankWebPartPage.aspx"}
foreach($page in $file.PageUrls)
{
$newPage=$pubweb.AddPublishingPage($page,$pageLayout);
$newPage.Update();
$newPage.CheckIn("Creating new page");
$newPage.ListItem.File.Publish("new page is created");
$web.Dispose();

Write-Host $page "Page is created" -ForegroundColor Green




text file(pageurls.txt):

PageUrls,
ISSAboutUs.aspx
ISSContactUs.aspx
ISSCustomerFirst.aspx
ISSVideos.aspx
ISSGenericCF.aspx
SolutionHub.aspx
ISSTechnotes.aspx



OutPut




No comments:

Post a Comment