Switch between modern SharePoint homepages using PnP PowerShell

I’ve been working on a modern intranet project amongst over projects for the last 12-months. This has been more about the transformation of content and business processes, rethinking information architecture and reimagining a modern intranet than it has been about custom development.

We’ve recently been testing variations in the design of a homepage with different audiences. This side-by-side comparison has allowed end-user feedback, performance and accessibility testing. The same approach has also been useful for previewing and testing the capabilities of new features (like the new Yammer web part). The challenge comes when you need to promote or switch over one of these variations as the new site homepage. The homepage is the page users are directed to when first navigating to a site or clicking on the site logo. It is like as important as the index.html or default.aspx page existence to a website. Note that these variations of the homepage permit testing of content and not site configuration. To test navigation, theme or similar we have separate sites and environments for this purpose.

To solve the problem switching the homepage from an existing page whilst preserving the home.aspx page name I’ve leveraged the SharePoint Pnp cmdlets to create a script that will rename or remove the current homepage (and can remove it through a toggle) and then rename an existing page to make it the new homepage.

Set-SPNewHomePage script demonstration
Demonstration of the Set-SPNewHomePage script in action.

Use my PnP PowerShell script to replace the home.aspx page

Alternative methods

Change the default homepage through SharePoint

Site Owners can use the out-of-the-box make homepage action to make any page the default homepage or welcome page. This is available from the toolbar in the site pages library. But this keeps the page name and means the default page is /sitepages/randompagename.aspx instead of the standard /sitepages/home.aspx that all sites have. From my perspective this is not great. Certainly, intranet-like sites should follow some basic content management principles. Call in a touch on the OCD side but consistently having a standard homepage is one of these for me.

Screenshot of setting a new homepage in the site pages library.
Screenshot of setting a new homepage in the site pages library.

Change the welcome page site property through Site Settings or PowerShell

Previously you could use the classic settings page (typically exposed by the publishing feature) or by browsing to /_layouts/15/AreaWelcomePage.aspx to make changes to the welcome page. This method no longer works and throws an error.

As with the make homepage action describe earlier this changes the default homepage to the use the page name you have provided and means the site won’t be available if users have bookmarked the site with the page name (/sitepages/home.aspx) in the URL.

Screenshot of the welcome page site settings page.
Screenshot of the welcome page site settings page.

What is my point? To this day can I still memory recall core settings pages. With these, you can quickly review or makes changes to settings pages rather than using the UI to navigate to them. This includes those that may no longer be exposed in the UI. Whilst my memory serves me well I don’t recommend this approach as these pages and settings are gradually being replaced with alternatives or removed by the SharePoint and Office 365 engineering team for a reason.

Instead, you can also use Pnp PowerShell to change the site welcome page property. I’ve provided an example script below.

As simple as my script is, it is the approach worth learning the most. I hope you find this article useful and as with all Pnp development effort. Sharing is caring!

My photography is available over at #500px

I’m spending more time with one of my favourite hobbies again – photography. You can browse my published portfolio over at 500px. Be sure to share your feedback.

Picture of the snow in Seattle, Feb 2019.
A snowy Pike Place Market, Seattle, Feb 2019 – before my accident.
See more of my photography over at 500px.com/jamescallaghan

Fondue with friends

This year I will be welcoming in the New Year with friends at home in Manchester. The last year has undoubtedly been a trying year. A year that has seen much change and I welcome all the challenges and change that 2019 will see.

I considered all kinds of recipes and food I wanted to cook for my friends, but a fondue and raclette grill was a clear winner for many reasons. The elves at Amazon kindly delivered an extended raclette grill that includes a fondue pan, grill and twelve raclette grills. I was keen to encourage games and conversation at the table but also have something that would have longevity as with New Year’s Eve, the evening is long. Food that was easy on the washing up was essential, as was the amount of time in the kitchen for me. The fondue and crudités can all be prepped beforehand if not the day before. Additional with the raclette grill and a hot plate for the fondue, the warmth in the food can be maintained throughout the evening. As with a lot of my cooking I really enjoy the research element to recipes and food, finding out what works well and what doesn’t etc but also very much enjoy sharing my recipes.

Fondue and Racelete research.
Fondue and Racelete research.

I wish friends new and old the best of luck for what 2019 brings and I thank you for all that you have done for me 2018.

Food with great friends.
Food with great friends.
Continue reading Fondue with friends

Chicken and vegetable egg fried rice

Last week I enjoyed a lovely Chinese meal out on my birthday in great company. The restaurant was incredible, as was the food. I wanted to eat everything. What I did eat was like nothing else I have had before, but it was the most simple of dishes that really hit my taste buds. A week on and I wanted to make a meal of one of the plates and decided to give Chicken and vegetable egg fried rice a go.

Serves: 2 ½
Prep Time: 25min
Cook Time: 15min

Ingredients

  • 2 cups of rice, cooked, drained and still warm
  • 1 large chicken breast, diced
  • 2 medium carrots, diced
  • 1 large onion, diced
  • 3 spring onions, diced
  • 3 eggs
  • 2 tbsp vegetable oil
  • 1 tsp dashi powder
  • 1 tsp crushed chicken stock cube
  • 1 tbsp minced garlic
  • 2 tsp unsalted butter
  • 2 tbsp soy sauce
  • 1 tbsp sesame oil
  • salt and pepper to taste

Method

Heat the wok until hot. Add some oil and once smoking add the eggs. Leave them to whiten before turning and scrambling using a spatula. Add the diced chicken and cook until it is 90% cooked through. Add the carrots and onions and keeping mixing in. Now add the warm rice and break down any large lumps. Now is the time to practice the wok flick!

Add a few pinches of salt and pepper, the garlic, dashi and chicken stock. Once mixed add the unsalted butter and a handful of spring onions. Now add the soy sauce and sesame oil while continuing to combine the ingredients together. Leave to cook for a few more minutes before serving with a sprinkle of spring onions as a garnish topping.

Fried rice ingredients prepared in bowls on a tray ready for cooking
The ingredients can be prepared ahead of cooking
A full plate of chicken and vegetable fried rice
A bowl of chicken and vegetable egg fried rice
Chicken and vegetable egg fried rice

PS the restaurant was called Tattu in Manchester.

Research and Inspiration