Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Create Colored Folders in SharePoint Online using CLI for Microsoft 365

In my previous blog post Creating Colored Folders in SharePoint Online and OneDrive, we saw how to create colored folders in SharePoint online document libraries and OneDrive for Business using user interface (UI) from browser. In this blog post, we’ll explore how to create colorful folders in SharePoint Online using CLI for Microsoft 365, a powerful command-line tool that extends SharePoint’s capabilities.

This new feature of coloring SharePoint & OneDrive folders allows users to assign a color label to folders, providing a visual cue for organization and categorization. However, it’s essential to understand how this works internally and what values are used for coloring folders in SharePoint Online and OneDrive for Business.

Thanks to Tetsuya Kawahara and his PnP PowerShell script sample at Create Colored Folder which explains SharePoint uses the column with internal name as _ColorHex to store the color setting information of folders. The _ColorHex field is a hidden field within SharePoint libraries, and it is not visible by default in standard views. This field stores the color as a numeric value corresponding to each color.

SharePoint supports a predefined set of 16 numerical color values that can be used to color folders. The following table shows the numerical values corresponding to each color:

Color_ColorHex value
YellowEmpty or 0
Dark red1
Dark orange2
Dark green3
Dark teal4
Dark blue5
Dark purple6
Dark pink7
Grey8
Light red9
Light orange10
Light green11
Light teal12
Light blue13
Light purple14
Light pink15

We will see how to use these _ColorHex column values to create a new folder in SharePoint online document library using CLI for Microsoft 365 below:

Step 1: Install the CLI for Microsoft 365

Before we can start working with the CLI for Microsoft 365, we need to install it. You can install the CLI for Microsoft 365 by using below NPM commands or by following the instructions on the official documentation page:  CLI for Microsoft 365 – Installation.

npm install -g @pnp/cli-microsoft365

You have to use below command if you want to install beta version of CLI for Microsoft 365:

npm install -g @pnp/cli-microsoft365@next

Step 2: Create colored folder using CLI for Microsoft 365

After installation of CLI for Microsoft 365,  you can use below CLI for Microsoft 365 script to create a new colored folder in SharePoint online document library using CLI for Microsoft 365:

# Set Variables
$siteUrl = "https://contoso.sharepoint.com/sites/work"
$relativeUrlOfParentFolder = "/ColoredFolders"
$documentLibraryDisplayName = "Colored Folders"
$folderName = "Confidential"
$folderColor = 1

try {
    # Get Credentials to connect to SharePoint Online site
    $m365Status = m365 status
    if ($m365Status -match "Logged Out") {
        m365 login
    }

    # Create the folder
    $newFolder = m365 spo folder add --webUrl $siteUrl --parentFolderUrl $relativeUrlOfParentFolder --name $folderName | ConvertFrom-Json

    # Get the created folder item
    $newFolderItem = m365 spo listitem get --webUrl $siteUrl --listTitle $documentLibraryDisplayName --uniqueId $newFolder.UniqueId | ConvertFrom-Json

    # Change the value of the _ColorHex column of the created folder to change the color
    m365 spo listitem set --webUrl $siteUrl --listTitle $documentLibraryDisplayName --id $newFolderItem.Id --_ColorHex $folderColor

    Write-Host "Folder created and color changed successfully." -ForegroundColor Green
    Write-Host "Folder URL: $siteUrl/$relativeUrlOfParentFolder/$folderName" -ForegroundColor Green
}
catch {
    Write-Host "An error occurred: $_" -ForegroundColor Red
}
finally {
    # Disconnect from SharePoint site
    m365 logout
}

Once you run above script successfully and navigate to SharePoint document library, you will see that new colored folder is created inside the SharePoint document library as given below: 

Create Colored Folders in SharePoint Online using CLI for Microsoft 365
Colored folders created in SharePoint Online using CLI for Microsoft 365

Conclusion

Adding color to your folders in SharePoint Online document libraries using CLI for Microsoft 365 is a simple yet effective way to enhance the visual organization and management of your documents. This can improve user experience and help users quickly identify and access the content they need. Experiment with different colors and organizational schemes to find what works best for your team or organization.

Learn more

Enable/Disable SharePoint Online List Comments using CLI for Microsoft 365

SharePoint Online lists are a great way to organize and manage data within your organization. They provide a flexible and customizable platform for teams to collaborate and share information. One of the features available in SharePoint Online lists / Microsoft Lists is the ability to add comments to list items. This can be a useful way to provide feedback, ask questions, or share information related to specific items within the list.

However, there may be situations where you want to disable comments for a particular list. This could be because you want to limit the amount of noise or clutter in the comments section, or because you want to encourage users to provide feedback in a different way.

In this blog post, we will walk through the steps required to enable or disable comments for a SharePoint Online list using the CLI for Microsoft 365.

Step 1: Install the CLI for Microsoft 365

Before we can start working with the CLI for Microsoft 365, we need to install it. You can install the CLI for Microsoft 365 by using below NPM commands or by following the instructions on the official documentation page:  CLI for Microsoft 365 – Installation. You have to install CLI for M365 v6.7.0 (beta) or higher.

npm install -g @pnp/cli-microsoft365

You have to use below command if you want to install beta version of CLI for Microsoft 365:

npm install -g @pnp/cli-microsoft365@next

Step 2: Enable or Disable Comments for a SharePoint Online List

To enable or disable comments for a SharePoint Online list, we have to use the m365 spo list set command in the CLI for Microsoft 365. The syntax for this command is as follows:

m365 spo list set --webUrl <site url> --title <list title> --disableCommenting <true/false>

Let’s break down each of these parameters:

  • --webUrl: The URL of the SharePoint Online site where the list is located.
  • --title: The title of the list you want to enable or disable comments for.
  • --disableCommenting: Set this to true to disable comments, or false to enable comments.

Here’s a complete CLI for Microsoft 365 script which you can use to disable comments for a SharePoint Online/Microsoft Lists modern experience list:

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

# Display name of SharePoint list
$listName = "Comments List"

# Get Credentials to connect to SharePoint site
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}
# Disable SharePoint online list comments
m365 spo list set --webUrl $siteUrl --title $listName --disableCommenting true

You can modify this CLI for M365 script to enable SharePoint list comments by changing the --disableCommenting parameter to false.

Once you run above script successfully, navigate to List Settings > Advanced Settings and you will find that commenting is disabled for your SharePoint online list:

SharePoint List Advanced settings showing disabled commenting on SharePoint Online list or Microsoft Lists using CLI for Microsoft 365
Disabled commenting on SharePoint Online list using CLI for Microsoft 365

Learn more

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

❌
❌