1

I'm wondering if it's possible to add an Index to a column in every Item of a specific Content Type.

I'm still having issues with the List View Threshold in an Intranet Site Collection so that CQWP's are failing to return items for users.

I thought I might be able to apply the indexing once rather than for every List that uses the Content Type in question Event

Thoughts?

1

Indexes are associated with List. So you need to modify the list and add index.

You can automate this using PowerShell.

$site = Get-SPsite http://siteurl 

foreach ($web in $site.AllWebs)  
{ 
    #foreach ($list in $web.Lists) 
    for ($i = 0; $i -lt $web.Lists.Count; $i++)
    {
        $list = $web.Lists[$i]
        foreach ($ct in $list.ContentTypes)  
        {  
            if ($ct.Name -eq "Your Content Type Name")  
            {  
                #Logic to create index 
                $field = $list.Fields["Field Name To Index"]
                $field.Indexed = $true
                $field.Update()
            } 
        } 
    }  
    $web.Dispose()  
} 
  • Thanks for that Amal. I'll test it and post back once I'm done. – N03L May 5 '15 at 12:46
  • It looks like I've failed to use your script. Initially I get an error, after the script appeared to be running, that states... "foreach : An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute.." I Googled this and found some suggestion that using a for loop rather than foreach would prevent the items collected earlier from being changed. I've not managed to make that work yet. – N03L May 5 '15 at 15:04
  • Ok in that case replace foreach with a for loop.. for($i=0;$i -lt $web.lists.Count; $i++).. Then use $list = $web.Lists[$i].. Check updated answer. – Amal Hashim May 5 '15 at 15:08
  • Thanks again Amal. That worked a treat. I'd already grabbed the for loop example but was failing to insert it in the correct place. – N03L May 6 '15 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.