1

So, I'm trying to create pages via powershell, script below:

 # Get the SiteURL
 $SiteUrl = "https://MySiteCollectionURL"

 # Get the WebURL
 $WebUrl = "https://MyWebURL"

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

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

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

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

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

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

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

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

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

 # Create a new publishing page.
 $Page = $PubWeb.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("Test Comment")

 # Publish the Page With Comments
 $Page.ListItem.File.Publish("Test Publish Comment")

Every time it gets to the AddPublishingPage command, it crashes out with the error:

Exception calling "AddPublishingPage" with "2" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

I have the 'shell window running as administrator, I'm a farm admin, and my account can create pages though the browser.

What gives?

  • Do you have access to the content Database ? – Ahmed Bouchaala Jan 28 at 15:49
  • Yeah, I'm basically a top-level admin on every area of the SharePoint farm. I'm wondering if I've set the Publishing site up wrong or something? – user1259798 Jan 28 at 16:36
1

Check below two things:

  1. You need to use "SharePoint 2013 Management Shell", not using "Windows PowerShell".

  2. Make sure you have a CustomPageLayout.aspx file in "Master Page Gallery" library. If not, using "BlankPageLayout.aspx".

Also you need to make sure you can access "Master Page Gallery" library

  • imp. - thanks for the tip - realised that the relative URL for the masterpages gallery was for the site, while my custom page was in the root site! stoopid... All fixed. ;) – user1259798 Jan 29 at 12:22

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.