Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Set SharePoint site home page using PnP PowerShell and CLI for Microsoft 365

SharePoint site home page provides a centralized location where users can access important information such as news, announcements, quick links and documents. This can help users stay informed and up-to-date on the latest company news and updates.

SharePoint site home page can be customized to include quick links to commonly used tools and applications, which can help users save time and increase productivity.

In this blog, we will look at how to use PnP PowerShell and CLI for Microsoft 365 to set a SharePoint modern page as the home page for SharePoint online site. You can use either of below scripts to make a newly created site page or an existing site page as the homepage for your SharePoint site.

Using PnP PowerShell

Once you have a modern site page ready in Site Pages library of your SharePoint site, you can use below PnP PowerShell script to make your site page as the homepage of your SharePoint site:

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Name of your SharePoint site page
$sitePageName = "NewHome.aspx"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Set SharePoint site home page using PnP PowerShell
Set-PnPHomePage -RootFolderRelativeUrl SitePages/$sitePageName

Using CLI for Microsoft 365

You can use below CLI for Microsoft script to set your site page as the homepage of your SharePoint online site:

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Name of your SharePoint site page
$sitePageName = "NewHome.aspx"

#Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}

# Set SharePoint site home page using CLI for Microsoft 365
m365 spo web set --url $siteUrl --welcomePage "SitePages/$sitePageName"

Note

You have to install latest versions of PnP PowerShell and CLI for Microsoft 365 before running above scripts. Follow below documentations for installing PnP PowerShell and CLI for Microsoft 365:

Once you run either of above scripts successfully and navigate to SharePoint online site, you will see that new home page is set for your SharePoint online site:

Set SharePoint online site home page using PnP PowerShell and CLI for Microsoft 365 in modern experience
Set SharePoint site home page using PnP PowerShell and CLI for Microsoft 365

Learn more

set-sharepoint-site-home-page-using-pnp-powershell-and-cli-for-microsoft-365

ganeshsanapblogs

Set SharePoint online site home page using PnP PowerShell and CLI for Microsoft 365 in modern experience

Poor Person’s Form Embedding in SharePoint Online Pages

In SharePoint – because it’s primarily a collaboration platform – we often struggle with the difference between security and obscurity.

Some content absolutely must be secured, meaning only certain people can see or edit it. In these cases, we set the permissions such that people simply can’t see or even be aware of the content.

Other content should just be kept out of the way by not showing links to it or including it in pages, and this can sometimes be referred to as obscurity. Audience targeting is a form of content management by obscurity: if the content isn’t of use to me, I may not see it, but that doesn’t mean I can’t get to it.

A very common business requirement is to allow people to provide some basic information, like a suggestion for a continuous improvement, their shirt or hat size for a company giveaway, or nominating someone for an award. We can configure the list which contain this information to only show the current user’s items in views, but that’s not necessarily security. If you need them, these settings are in List settings / Advanced settings / Item-level Permissions.

But that’s not the main point of this post. Sometimes the forms are simple and the process is not consequential enough to deserve a Power App or more complex form development. We just want to make the plain old list form available for people to use easily and shield them from the complexity of the underlying list itself. I see solutions all the time where the user is sent to a list view with tacit belief they will know to click the +New button to create a new item in the list. In many workforces, even that is too complicated.

Sometimes Occam’s Razor applies: the simplest solution is the best one.

This is a trick I’ve used many times to make life easier for users and also keep them from plumbing around in the underlying list, even though they may be able to do so due to the permission settings being pretty open.

Some advice, though…

Don’t stick a form like this on the home page of an Intranet site unless you want everyone to see that form as the primary focus for the entire site. I would argue this is rarely the case. In my example, the Suggestion Box is part of the Continuous Improvement site. That effort has to have more to it than just the form.

Here’s the trick. I’m sure I’m not the first person to come up with it, and Emily (@eemancini) probably taught it to me in the first place!

  • Create a new page in the site and add some explanatory text and imagery. Let your users know what you’re asking them to do and why it’s useful. A “naked” form doesn’t give them any context.
  • Add an Embed Web Part to the page with a URL something like this: https://sympmarc.sharepoint.com/sites/SuggestionBox/Lists/SuggestionBox/NewForm.aspx?Source=https://sympmarc.sharepoint.com/sites/SuggestionBox/Lists/SuggestionBox/NewForm.aspx I’ll break that down below.
  • Add a navigation element to the home page of your site to take people to this page.

That ugly URL has the following parts:

  • https://sympmarc.sharepoint.com/sites/SuggestionBox/Lists/SuggestionBox/NewForm.aspx – The list’s new item form you want to load in the page. All lists have forms pages, and have since SharePoint 2007:
    • https://sympmarc.sharepoint.com – Your SharePoint subdomain. This is my personal tenant.
    • /sites/SuggestionBox/ – The site where the list lives.
    • Lists/SuggestionBox/ – The list itself. All SharePoint lists live under the /Lists part of the URL path. (Document Libraries don’t.)
    • NewForm.aspx – This is the form you get when you click the +New button on the list pages.
  • ?Source=https://sympmarc.sharepoint.com/sites/SuggestionBox/Lists/SuggestionBox/NewForm.aspx – Values after the ? are what’s called the query string. Manipulating what’s hdre has been a nice little arrow in the quiver for years. They are name/value pairs, so here we have:
    • Source – This is a special parameter name when it comes to SharePoint lists. It basically says “when you’re done here, redirect to the following URL”)
    • https://sympmarc.sharepoint.com/sites/SuggestionBox/Lists/SuggestionBox/NewForm.aspx – Yup, that’s the same link we’re loading above.

Your page will look something like this:

As you can see, the form is embedded directly in the page. In actuality, it’s housed inside something called an iframe. You may have heard developers disparaging iframes in the past, but in this case, it works just the way we want it to.

When the user fills out the form and clicks Save, guess where they end up? Right in the same place! So they can submit one or more items – in this case suggestions – without ever knowing there’s a SharePoint list under the covers.

Have you used a trick like this in the past? Do you have any improvements to suggest about this technique?

❌
❌