3

I want to delete the pages from the MySite page library and add new pages to that library.

How to do it with PowerShell?

2

Use the below PowerShell script

# Add the PowerShell Snapin  

 $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}  

 if ($snapin -eq $null)   
 {   
     Add-PSSnapin "Microsoft.SharePoint.Powershell"  
 }  

 # Get the SiteURL  
 $SiteUrl = "https://Thegowtham.sharepoint.com"  

 # Get the WebURL  
 $WebUrl = "https://the gowtham.sharepoint.com/sites/TS"  

 # Get the PageLayout  
 $PageLayoutRelUrl = "/_catalogs/masterpage/CustomPageLayout.aspx"  

 # Get the Page URL  
 $PageName = "TestSite.aspx"  

 # Get the Title of the Page which is going to get created  
 $PageTitle = "SamplePage"  

 # Initialize the Site Object  
 $Site = Get-SPSite($SiteUrl)  

 # Get the Publishing Site based on the SPSite  
 $PublishingSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Site)  

 # Get the SPWeb Object  
 $Web = Get-SPWeb $WebUrl  

 # Initialize the PublishingWeb based on the SPWeb  
 $PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)  

 # Get the PageLayouts Installed on the Publishing Site  
 $Layouts = $ PublishingSite.GetPageLayouts($False)  

 # Get our PageLayout  
 $PageLayout = $Layouts[$PageLayoutRelUrl]  

 # Create a new publishing page.  
 $Page = $ PublishingWeb.AddPublishingPage($PageName, $PageLayout)  

 # Assign the Title for the Page  
 $Page.Title = $PageTitle  

 # Update the Page  
 $Page.Update();  

 # Check in the Page with Comments  
 $Page.CheckIn("Page Created Successfully")  

 # Publish the Page With Comments  
 $Page.ListItem.File.Publish("Page Created Successfully and  Publish Comment") 

Reference : http://www.c-sharpcorner.com/blogs/powershell-script-to-create-publishing-page-using-custom-pagelayout-in-sharepoint-2013 https://social.msdn.microsoft.com/Forums/sharepoint/en-US/b6fb9c11-c5df-4efb-ab59-2596810eb400/how-to-add-new-page-to-sitepages-list?forum=sharepointdevelopmentlegacy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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