pnp / pnp/powershell

Add-PnPPage: Object reference not set to an instance of an object when trying to create a new page

Open
#3,959 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
904
Forks
407
Avg merge
9h 16m
Merged PRs (30d)
10

Description

Category

  • Bug

Describe the bug

Im trying to migrate a classic site into a modern one. I already have the connected 365 group and i can use modern lists and libraries. But i have pages, like the homepage that are classic and when this page is displayed the menu is the classic one too so the user is confused. I dont want to migrate any of those pages, i tried and get other errors so i delete all of them. Now, im trying to create a new modern page using PnP. Im using command Add-PnPPage.

Steps to reproduce

DELETE THIS LINE BEFORE SUBMITTING - Provide steps to reproduce the behavior:

  1. Im using powershell 7 and PnP installed yesterday version 2.4.0
  2. Auth using Connect-PnPOnline -Url "https://----.sharepoint.com/calidad" -Credential (Get-Credential)
  3. Execute command $pagename = "Welcome"
  4. Execute command $page = Add-PnPPage -Name $pagename -LayoutType Home
  5. See error: Add-PnPPage: Object reference not set to an instance of an object.

Expected behavior

The modern page to be created. A file is created instead but is corrupted.

Environment details (development & target environment)

  • SDK version: 2.4.0
  • OS: Windows 11
Additional context

What i want to achieve is my users only have to see one menu, and not be changing between different designs. I can't recreate the entire site because it has a lot of list with powerautomate flows.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with Connect-PnPOnline and Add-PnPPage -Name "Welcome" -LayoutType Home against the reported environment. Inspect the Add-PnPPage entry point and the generated file behavior; done means the command creates a usable modern page instead of raising the null-reference error and producing a corrupted file.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.