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

SharePoint Online: Apply JSON View formatting using PnP PowerShell

SharePoint online JSON view formatting is a powerful feature that allows you to customize the look and feel of your SharePoint lists and libraries. In my previous article I explained how to apply JSON View formatting using SharePoint REST API. In this article, we will see how you can easily apply JSON view formatting to your SharePoint lists and libraries using PnP PowerShell from the command line.

The first step in applying SharePoint JSON view formatting using PnP PowerShell is to install PnP PowerShell module on your machine. To install PnP PowerShell, open a PowerShell console as an administrator and run the following command (or follow this article – Installing PnP PowerShell):

Install-Module PnP.PowerShell -Scope CurrentUser

For this blog post, we will use below view formatting JSON as an example:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
    "additionalRowClass": "=if([$PublishDate] <= @now && [$IsPublished] == false, 'sp-field-severity--severeWarning', '')"
}

If you use this view formatting JSON directly in below PnP PowerShell script, you may get errors like:

Set-PnPView: Name cannot begin with the ‘=’ character, hexadecimal value 0x3D.

OR

Set-PnPView: An error occurred while parsing EntityName.

To avoid such errors you have to use HTML/XML character encoding for JSON formatting operators like <, >, &&, etc.

OperatorEncoded character
<&lt;
>&gt;
&&amp;

After HTML/XML character encoding, above view formatting JSON will be converted to this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if([$PublishDate] &lt;= @now &amp;&amp; [$IsPublished] == false, 'sp-field-severity--severeWarning', '')"
}

Then you can use below PnP PowerShell script to apply JSON View formatting to your SharePoint online list:

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

# Display name of SharePoint list
$listName = "Ganesh Sanap Blogs"

# Name of SharePoint list view
$viewName = "All Items"

# JSON to apply to view formatting
$jsonViewFormatting = @'
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if([$PublishDate] &lt;= @now &amp;&amp; [$IsPublished] == false, 'sp-field-severity--severeWarning', '')"
}
'@

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

# Apply JSON view formatting
Set-PnPView -List $listName -Identity $viewName -Values @{CustomFormatter = $jsonViewFormatting}

Where [$PublishDate] and [$IsPublished] are the internal names of your SharePoint columns.

Once you run above script successfully and navigate to SharePoint list view, you will see that new JSON view formatting is applied to your SharePoint online list view using PnP PowerShell:

SharePoint Online Modern experience Apply JSON View formatting using PnP PowerShell
SharePoint Online: Apply JSON View formatting using PnP PowerShell

Learn more

sharepoint-online-apply-json-view-formatting-using-pnp-powershell

ganeshsanapblogs

SharePoint Online Modern experience Apply JSON View formatting using PnP PowerShell

❌
❌