Add-PnPPage: Object reference not set to an instance of an object when trying to create a new page
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:
- Im using powershell 7 and PnP installed yesterday version 2.4.0
- Auth using
Connect-PnPOnline -Url "https://----.sharepoint.com/calidad" -Credential (Get-Credential) - Execute command
$pagename = "Welcome" - Execute command
$page = Add-PnPPage -Name $pagename -LayoutType Home - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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