How to publish a pagelayout html file? I have a pagelayout which exists about 2 files:

  • customPageLayout.html
  • customPageLayout.aspx

In the gui it is only possible to publish the html file. The aspx file will be automatically modified and published.

How to publish these 2 files in powershell?

2 Answers 2


To publish page layout via PowerSell , Try to run the following Script :

$web = Get-SPWeb http://yoursitecollection

$pages = "http://yoursitecollection/_catalogs/masterpage/customPageLayout.html"

$pages | ForEach-Object { $item = $web.GetListItem($_)
    if ($item.File.CheckOutType -ne "None")
        $item.File.CheckIn("checked in", "CheckIn");
    if ($item.Versions[0].Level -ne "Published")


To make sure that it's published successfully , open http://sitecollection/_layouts/15/DesignPageLayouts.aspx click on ... check the sub menu , you should get Unpublish this version

enter image description here

  • thanks this works. Is this also possible with office dev pnp powershell?
    – Ola
    Oct 9, 2016 at 14:34
  • Hi @Ola, I tried this on SharePoint 2013 on-prem that worked propely for me and and based on your feedback, but it's not work with Office 365 Developer Patterns and Practices because the command is different from on-prem Get-SPWeb = and SP online Get-SPOWeb but I think this link may help you gallery.technet.microsoft.com/office/… and this github.com/OfficeDev/PnP-PowerShell , I am sorry I don't have SharePoint online now to try it , anyway if the links do not help you, please ask this in new question, and more participants will help you, Oct 9, 2016 at 17:58
  • I use SP 2013 on-prem. Office Dev Pnp powershell can be used also for on-prem.
    – Ola
    Oct 10, 2016 at 9:53
  • you are right ,dev Pnp worked for both, but I talk about if this will work for SP online or not ? and to be honest I don't try to work with dev Pnp more, so should you ask at community if it's possible or not , hope you find the accurate answer , meanwhile, I will try to find answer for this :) Oct 10, 2016 at 23:47

this is the solution to publish the html design files with office dev pnp powershell:

Loop into the folder where the html design files are stored. In my situation it is a subfolder in the masterpage gallery. Filter on design html files. For each html design file check it out. Update it to create the associated aspx file. Check it in as a major version (publish). From this point your pagelayout or masterpage can be used.

# Retrieve the folder structure
    $folder = Get-SPOFolderItem $url

    # Loop through the folder (subfolders and files)
    $folder | foreach {

        # Is it a folder, recursive call CheckInItem

            # Retrieve all the field of the file
            Get-SPOProperty -ClientObject $_ -Property ListItemAllFields

            # If it is and HtmlDesign locked file we need to skip it
            if($_.ListItemAllFields.FieldValues.MetaInfo -match "HtmlDesignLockedFile"){

            } else {
                # Check if the file needs to be checked out
                if($_.CheckOutType -eq "None"){
                    Set-SPOFileCheckedOut -Url $_.ServerRelativeUrl

                # update list item to create assocation (aspx) file
                $masterpageGalleryList = Get-SPOList -Identity /_catalogs/masterpage

                    Set-SPOListItem -List $masterpageGalleryList -Identity $_.ListItemAllFields.Id -Values @{}

                # Publish the file
                Set-SPOFileCheckedIn -Url $_.ServerRelativeUrl -CheckinType MajorCheckIn


    } > $null
  • Hi @Ola Great job, and I would like to tell you that this answer should be at this question where you mention you need to use PNP , to be helpful for all sharepoint.stackexchange.com/questions/196455/… , meanwhile, at this thread you need to do this via PowerShell and don't mention you need to use PNP and you comment at my answer it's worked , so why you remove set as answer although my answer is correct based on your feedback :) , I think I tried to help you based on your question, Oct 11, 2016 at 14:43
  • 1
    ok I will change it and mark your answer as the solution. Thanks for your help.
    – Ola
    Oct 12, 2016 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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