How to create indexed column in SharePoint list using PowerShell and how to remove indexed column from SharePoint online list using PowerShell?

how to create indexed column in sharepoint list using PowerShell

Here we will discuss:
– How to create Indexed column in SharePoint online list using PowerShell?
– How to remove indexed column in SharePoint online list using PowerShell?

If you are new to SharePoint indexed column, then check out the below articles to know about what is an indexed column in SharePoint? Benefits of using indexed column in SharePoint online list? How we can create indexed column using browser and also how we can create indexed column using .Net managed object model code (csom).
Working with Indexed column in SharePoint Online

SharePoint online create index in list using CSOM .Net managed object model code using visual studio 2015

In this particular blog post we will discuss how we can create and remove indexed column using PowerShell in SharePoint online list.

How to create Indexed column in SharePoint online list using PowerShell?

In my SharePoint online site, I have a list name as Logging (custom list) and if I will check there is not indexed column associated with the list. To check this, go to the List Settings page and then click on Indexed columns link down above Views section. Then you can see there are not index columns are there like below:

how to create indexed column in sharepoint list using PowerShell
how to create indexed column in sharepoint list using PowerShell

Now below is the PowerShell script to create the indexed column. Here we are first retrieving the list column and then we are setting the indexed column by using $field.Indexed = $true.



You can run and debug the PowerShell script by using Windows PowerShell ISE.

Add-Type -Path “E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

$siteUrl = “https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString “*****” -AsPlainText -Force
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials(“bijay@onlysharepoint2013.onmicrosoft.com”, $securePassword)

$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()

$list = $ctx.Web.Lists.GetByTitle(‘Logging’)

$field = $list.Fields.GetByTitle(‘Title’)
$field.Indexed = $true
$field.Update()
$ctx.ExecuteQuery()

Once you execute the above script, you can see it will create one indexed column as “Title” like below:

sharepoint 2013 create list indexed column using powershell
sharepoint 2013 create list indexed column using powershell

Remove indexed column from SharePoint Online list using PowerShell:

We can also easily remove indexed column from SharePoint online list using PowerShell. By using the below PowerShell script we can remove the indexed column which we have created above.

Add-Type -Path “E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

$siteUrl = “https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString “**********” -AsPlainText -Force
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials(“bijay@onlysharepoint2013.onmicrosoft.com”, $securePassword)

$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()

$list = $ctx.Web.Lists.GetByTitle(‘Logging’)

$field = $list.Fields.GetByTitle(‘Title’)
$field.Indexed = $false
$field.Update()
$ctx.ExecuteQuery()

Once you run the above script, it will remove the indexed column from the list. You can see below:

Remove indexed column in sharepoint online list using PowerShell
Remove indexed column in sharepoint online list using PowerShell

Hope this article will be helpful.


About Bijay Kumar

I am Bijay from Odisha, India. Currently working with a reputed organization in Bangalore. I am Microsoft Office Servers and Services (SharePoint) MVP (4 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.

View all posts by Bijay Kumar →

Leave a Reply

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