Vue normale

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

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

Enable/Disable SharePoint Online List Comments using PnP PowerShell

In my previous blog we saw how you can enable/disable SharePoint online list comments using SharePoint REST API. In this blog, let us see how you can enable/disable the commenting in SharePoint Online/Microsoft Lists using PnP PowerShell.

We can use Set-PnPList cmdlet in PnP PowerShell to update SharePoint list settings/properties. However Set-PnPList cmdlet does not support any parameter to enable/disable SharePoint online list comments yet. So, we have to use different approach to disable the SharePoint online list comments as shown below:

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

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

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Get the SharePoint online list 
$list = Get-PnPList -Identity $listName
 
# Disable SharePoint online list Comments
$list.DisableCommenting = $true
$list.Update()
Invoke-PnPQuery

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:

List Advanced settings showing disabled commenting on SharePoint Online list or Microsoft Lists using SharePoint REST API
Disabled commenting on SharePoint Online list or Microsoft Lists

If you have disabled the SharePoint online list comments previously and now you want to enable them back, you have to use PnP PowerShell script like below:

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

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

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Get the SharePoint online list 
$list = Get-PnPList -Identity $listName
 
# Disable SharePoint online list Comments
$list.DisableCommenting = $false
$list.Update()
Invoke-PnPQuery

Update

It is now possible to enable/disable SharePoint online list comments using Set-PnPList cmdlet. You have to install 2.0.51-nightly or higher version of PnP PowerShell.

If you want to install or update to the latest nightly built prerelease of PnP PowerShell, run:

Install-Module PnP.PowerShell -AllowPrerelease

Then you can disable SharePoint online list comments using below PnP PowerShell script:

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

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

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Disable SharePoint online list Comments
Set-PnPList -Identity $listName -DisableCommenting $true

I hope you liked this blog. Give your valuable feedback & suggestions in the comments section below and share this blog with others.

See also

How to Enable/Disable the commenting in SharePoint Online/Microsoft Lists

In my previous blog about Commenting in SharePoint Online and Microsoft lists, I explained where you can find the comments options, what are the permission considerations, working with commenting using SharePoint REST APIs and JSON formatting, etc. In this blog I will explain how you can enable/disable the commenting in SharePoint Online/Microsoft Lists.

Commenting in lists is a great feature which will help many organizations. However, it’s possible that some organizations may want to disable this feature as they already have some mechanism in place for commenting, for example approvals system as mentioned here.

Currently it is not possible to disable commenting at the SharePoint site or list level (possible as of June 2021). Microsoft is working on the new feature which will allow users to enable/disable the comments for individual SharePoint lists.

However, Admins can enable/disable this feature at the organization level by changing the CommentsOnListItemsDisabled parameter in the Set-SPOTenant PowerShell cmdlet:

# To disable comments on list items
Connect-SPOService -Url https://<tenant>-admin.sharepoint.com/ 
Set-SPOTenant -CommentsOnListItemsDisabled $true

# To enable comments on list items
Connect-SPOService -Url https://<tenant>-admin.sharepoint.com/ 
Set-SPOTenant -CommentsOnListItemsDisabled $false

Replace <tenant> with the name of your Microsoft 365 tenant.

Using PnP PowerShell

You can also use PnP PowerShell to enable or disable commenting in SharePoint Online/Microsoft Lists at tenant level:

# Connect to SharePoint online admin center
Connect-PnPOnline -Url https://<tenant>-admin.sharepoint.com/ -Interactive

# To disable comments on list items
Set-PnPTenant -CommentsOnListItemsDisabled $true

# To enable comments on list items
Set-PnPTenant -CommentsOnListItemsDisabled $false

Using CLI for Microsoft 365

Use below CLI for Microsoft 365 script to enable or disable commenting in SharePoint Online/Microsoft Lists at tenant level:

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

# To disable comments on list items
m365 spo tenant settings set --CommentsOnListItemsDisabled true

# To enable comments on list items
m365 spo tenant settings set --CommentsOnListItemsDisabled false

Note: You must be a SharePoint Administrator or Global Administrator in your tenant to enable/disable this feature using PowerShell.

I hope you liked this blog. Give your valuable feedback & suggestions in the comments section below and share this blog with others.

See also

Enable/Disable SharePoint Online List Comments using SharePoint REST API

Commenting feature in lists is enabled by default when you create a new list in SharePoint online site or in “My lists” under Microsoft Lists. However you may want to disable the commenting feature if you are using multiple lines of text column with “Append Changes to Existing Text” functionality or if you are capturing comments by Power automate approvals. 

In my earlier blogs, I explained how to enable/disable the comments in SharePoint Online lists for entire tenant using SharePoint Online PowerShell & PnP PowerShell and how to enable/disable the comments for individual SharePoint lists from SharePoint UI via browser.

In this blog I will explain how you can enable/disable the commenting in SharePoint Online/Microsoft Lists using SharePoint REST API. We can retrieve SharePoint list and update list properties with lists endpoint like below using SharePoint REST API:

https://contoso.sharepoint.com/sites/SPConnect/_api/web/lists/getbytitle('Comments List')

Using above endpoint we will update list property named DisableCommenting which allows us to enable/disable SharePoint online list commenting. We have to use the list properties payload like below:

var listProperties = {
	"__metadata": {
		"type": "SP.List"
	},
	"DisableCommenting": true
}

Complete Code

Below is the complete code to disable the commenting in individual SharePoint Online/Microsoft Lists “list” using SharePoint REST API:

function disableListComments(listName) {
	var listEndpoint = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')";

	var listProperties = {
		"__metadata": {
			"type": "SP.List"
		},
		"DisableCommenting": true
	}

	$.ajax({
		url: listEndpoint,
		type: "POST",
		headers: {
			"accept": "application/json;odata=verbose",
			"content-type": "application/json;odata=verbose",
			"X-RequestDigest": $("#__REQUESTDIGEST").val(),
			"X-HTTP-Method": "MERGE",
			"If-Match": "*"
		},
		data: JSON.stringify(listProperties),
		success: function(data) {
			console.log(data);
		},
		error: function(error) {
			console.log(error);
		}
	});
}

You can call this function like given below:

disableListComments('Comments List')

Once above function executes successfully, navigate to List Settings > Advanced Settings and you will see that commenting is disabled for your SharePoint online list:

List Advanced settings showing disabled commenting on SharePoint Online list or Microsoft Lists using SharePoint REST API
Disabled commenting on SharePoint Online list or Microsoft Lists

I hope you liked this blog. Give your valuable feedback & suggestions in the comments section below and share this blog with others.

See also

❌
❌