SharePoint Online: Format List View using PowerShell

Requirement: Apply formatting to SharePoint Online View using PowerShell.

How to Apply Formatting to a List View in SharePoint Online?

Similar to column formatting, we can apply formatting to SharePoint Online views as well. Say, you want to apply alternate rows highlighting format for a SharePoint Online list view. Here are the steps to apply formatting to a list view:

  1. Login to your SharePoint Online site >> Navigate to the list and pick the target view you would like to format.
  2. In the Views dropdown, select “Format current View”.format list view in sharepoint online
  3. Apply the JSON to format the view. Preview the results and hit the “Save” button once finalized.alternate rows sharepoint online list view

PowerShell to Set List View Formatting

Alright, How about setting the view format using PowerShell? Here is the PowerShell script to apply formatting to a SharePoint list view:

$SiteURL = ""
$ListName = "Projects"
$ViewName = "Active Projects"

$JSONFormat = @"
  "$schema": "",
  "additionalRowClass": "=if(@rowIndex % 2 == 0,'ms-bgColor-themeLighter ms-bgColor-themeLight--hover','')"
    #Connect to site
    Connect-PnPOnline -URL $SiteURL -Interactive
    #Set the View Formatting
    Set-PnPView -List $ListName -Identity $ViewName -Values @{CustomFormatter =$JSONFormat} -ErrorAction Stop
    Write-host "View Format Applied Successfully!" -foregroundcolor Green
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

Use this GitHub resource for list view formats from the community:

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “SharePoint Online: Format List View using PowerShell

  • SharePoint Online: Format List View using PowerShell – Is this possible to achieve using SPO CSOM, not PnP? If yes, could you please show/share the required code?

    • per this documentation
      the View object suppose to have a CustomFormatter attribute. But when I try to add anything it says the property doesn’t exist on that object.

      3 thoughts:
      – the CustomFormatter is a RemoteAttribute, so it perhaps needs to be loaded differently?
      – maybe would be useful to have a look on the PnP source code, on how it is done. I believe they use CSOM in the background
      – it should be also possible to use Graph API


Leave a Reply

Your email address will not be published. Required fields are marked *