Quantcast
Channel: Creating a new blank page with a text web part in SharePoint Online using PowerShell - SharePoint Stack Exchange
Viewing all articles
Browse latest Browse all 2

Creating a new blank page with a text web part in SharePoint Online using PowerShell

$
0
0

I'm quite new to using PowerShell and SharePoint, and I've been running into issues creating a new page on a subsite. I've been trying to follow code I found here: https://sharepointstew.wordpress.com/2015/03/09/csom-powershell-to-create-a-sharepoint-publishing-page-with-custom-or-oob-page-layout/and here: https://www.sharepointdiary.com/2018/04/sharepoint-online-create-publishing-page-using-powershell.html

I think the issue is that it's trying to find blank web part.aspx in the master page gallery in my subsite, however, checking there I have no blankwebpart.aspx files there or in the root webmaster page gallery. I've also tried running it on my root web with DefaultLayout.aspx but still the same issues. I'm kind of at a loss for how to proceed, here are some of the errors I'm running into:

function returnThings($Context) {    $List = $Context.Web.Lists    $Context.load($List)    $Context.executeQuery()    $mpList = $List.GetByTitle("Master Page Gallery")    $PageLayoutName = "DefaultLayout.aspx"    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery    $camlQuery.ViewXml = '<View><Query><Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">'+ $PageLayoutName +'</Value></Eq></Where></Query></View>'    $items = $mpList.GetItems($camlQuery)    $Context.Load($items)    $Context.ExecuteQuery()    $pageLayoutItem = $items[0]    $Context.Load($pageLayoutItem)    foreach ($PageL in $items) {        write-host "See below: " -ForegroundColor Blue        $PageL | ConvertTo-Csv    }    # Get publishing web object    #    $web = $Context.Web    $pubWeb = [Microsoft.SharePoint.Client.Publishing.PublishingWeb]::GetPublishingWeb($Context, $web)    $Context.Load($pubWeb)    #Get pages library.    $pagesList = $Context.Web.Lists.GetByTitle("Pages")    $PageName = "Project Deviations"    $pubPageInfo = New-Object Microsoft.SharePoint.Client.Publishing.PublishingPageInformation    $pubPageInfo.Name = $PageName.Replace("", "-") +".aspx"    $pubPageInfo.PageLayoutListItem = $pageLayoutItem     $pubPage = $pubWeb.AddPublishingpage($pubPageInfo)    $pubPage.ListItem.File.CheckIn("", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)    $pubPage.ListItem.File.Publish("")    $pubPage.ListItem.File.Approve("")    $Context.Load($pubPage)     $Context.ExecuteQuery()}
Exception calling "ExecuteQuery" with "0" argument(s): "List 'Pages' does not exist at site with URL'https://companydemo2.sharepoint.com/sites/TEAM'."At C:\Users\conormo\Documents\Sharepoint Repos\KcentralMigration\Scripts\testProjDeviations.ps1:70 char:5+     $Context.ExecuteQuery()+     ~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ServerException

I'm using the SharePoint Online management shell and have the SharePoint dll's installed and all. I'm sure I'm missing something plainly obvious here, cheers


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images