How To Set The Indexing To Columns In SharePoint 2013 Using PowerShell Commands

Steps

Start your Windows PowerShell on your computer.

Right click and select run as an administrator option.

Paste the script given below on PowerShell Window and click the enter button.

Check your SharePoint site feature, which will be activated successfully.
  1. Function AddIndex ()   
  2. {   
  3. Param ($listname,$InternalFieldName)   
  4.    
  5.     try   
  6.         {   
  7.         Write-Host "Retriving the field $InternalFldName";   
  8.    
  9.         $fieldToIndex =$list.Fields.GetFieldByInternalName($InternalFldName);                                                    
  10.    
  11.         Write-Host $fieldToIndex has been found";   
  12.    
  13.             try   
  14.             {   
  15.                $index= $list.FieldIndexes.Item($fieldToIndex.Id)   
  16.                Write-Host $fieldToIndex is already indexed"   
  17.             }   
  18.             catch   
  19.             {   
  20.                 $fldToIndex.Indexed = $true;       
  21.                 $list.FieldIndexes.Add($fldToIndex);   
  22.                 Write-Output ("The field {0} has been indexed" -f  $fldToIndex.Title);   
  23.             }   
  24.    
  25.         }   
  26.     catch   
  27.         {   
  28.          $error[0]   
  29.         }   
  30.    
  31. }