Alternative colors for folders will be enabled in OneDrive and SharePoint. I got some requests about ways to set up the colors via PowerShell.
Content
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.
Color configuration for SharePoint folders with PowerShell
The easiest way to change the color of a folder is with PowerShell via PnP.PowerShell.
- Connect to the SharePoint site with PnP.PowerShell.
Import-Module PnP.PowerShell
Connect-PnPOnline -Url <SiteUrl> -Interactive
- Load your folder via Get-PnPFolder and include Properties for the query.
$Folder = Get-PnPFolder -Url "Documents/ColoredFolder" -Includes "Properties"
- You can find the property vti_colorhex in the properties of the folder. The default color 0 was defined for my folder.
$Folder.Properties.FieldValues.GetEnumerator() | ?{$_.Key -eq "vti_colorhex" }
$Folder.Properties.FieldValues["vti_colorhex"]
- Set-PnPPropertyBagValue can be used to quickly adjust the number and folder color in the property.
Set-PnPPropertyBagValue -Folder "Documents/ColoredFolder" -Key "vti_colorhex" -Value 1
The color of the folder will be adjusted immediately.