Create Colored Folder
Summary
Colored Folders can be created in OneDrive for Business and SharePoint document libraries.
Note
Colored Folder is a feature in deployment as of September 3, 2023 and may not be available to your tenant. (Microsoft Roadmap ID 124980)
The folder's color setting information is stored in the _ColorHex
column. This _ColorHex
column is then set to the numeric value corresponding to each color. The following is a table of the numerical values corresponding to each color:
Color | _ColorHex value |
---|---|
Yellow | Empty or 0 |
Dark red | 1 |
Dark orange | 2 |
Dark green | 3 |
Dark teal | 4 |
Dark blue | 5 |
Dark purple | 6 |
Dark pink | 7 |
Grey | 8 |
Light red | 9 |
Light orange | 10 |
Light green | 11 |
Light teal | 12 |
Light blue | 13 |
Light purple | 14 |
Light pink | 15 |
This sample code creates a new folder in the SharePoint document library, sets the value of the _ColorHex
column of the created folder, and changes the folder's color.
# Set Variables
$siteUrl = "https://contoso.sharepoint.com/sites/Marketing"
$documentLibrary = "Documents"
$folderName = "FolderA"
$folderColor = 3
try {
# Connect to SharePoint site
Connect-PnPOnline -Url $siteUrl -Interactive -ErrorAction Stop
# Create the folder
$newFolder = Add-PnPFolder -Name $folderName -Folder $documentLibrary -ErrorAction Stop
# Get the created folder item
$newFolderItem = Get-PnPListItem -List $documentLibrary -UniqueId $newFolder.UniqueId -ErrorAction Stop
# Change the value of the _ColorHex column of the created folder to change the color
Set-PnPListItem -List $documentLibrary -Identity $newFolderItem.Id -Values @{"_ColorHex" = $folderColor } -ErrorAction Stop
Write-Host "Folder created and color changed successfully." -ForegroundColor Green
Write-Host "Folder URL: $siteUrl/$documentLibrary/$folderName" -ForegroundColor Green
}
catch {
Write-Host "An error occurred: $_" -ForegroundColor Red
}
finally {
# Disconnect from SharePoint site
Disconnect-PnPOnline
}
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Tetsuya Kawahara |
Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.