Configure SharePoint folder colors with PowerShell

Alternative colors for folders will be enabled in OneDrive and SharePoint. I got some requests about ways to set up the colors via PowerShell.


Information about the configuration of colors per folder

SharePoint stores the color with a number from 0 to 15 in the vti_colorhex property of the folder. So far, I found no documentation of which number represents which color. Therefore, I tried all 16 colors.

  • SharePoint counts the colors from 0 to 15.
  • 0 is yellow, the default color of a folder.
  • From 16 it is also yellow, currently set equal to 0.

As a result, it is the following evaluation of numbers for the colors.

Numbers for folder color in SharePoint and OneDrive
Numbers for folder color in SharePoint and OneDrive
Color configuration for SharePoint folders with PowerShell

The easiest way to change the color of a folder is with PowerShell via PnP.PowerShell.

  1. Connect to the SharePoint site with PnP.PowerShell.
PowerShell
Import-Module PnP.PowerShell
Connect-PnPOnline -Url <SiteUrl> -Interactive

  1. Load your folder via Get-PnPFolder and include Properties for the query.
PowerShell
$Folder = Get-PnPFolder -Url "Documents/ColoredFolder" -Includes "Properties"

  1. You can find the property vti_colorhex in the properties of the folder. The default color 0 was defined for my folder.
PowerShell
$Folder.Properties.FieldValues.GetEnumerator() | ?{$_.Key -eq "vti_colorhex" }
$Folder.Properties.FieldValues["vti_colorhex"]

PowerShell
  1. Set-PnPPropertyBagValue can be used to quickly adjust the number and folder color in the property.
PowerShell
Set-PnPPropertyBagValue -Folder "Documents/ColoredFolder" -Key "vti_colorhex" -Value 1


The color of the folder will be adjusted immediately.

New color for the folder
New color for the folder
Share
Avatar photo

Tobias Asböck

Tobias is a Senior System Engineer with around ten years of professional experience with Microsoft 365 products such as SharePoint Online, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. Tobias is a PowerShell Scripter with certifications for Microsoft 365 products. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities. If you have additional questions, please contact me via LinkedIn or [email protected].

Leave a Reply

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