On SP 2013 on prem, I am using PowerShell script to add indexed columns to a list. I have managed to add that, like this:

    $siteUrl = "http://url" 
    $web = Get-SPWeb $siteUrl
    $listName = "List"
    $list = $web.Lists.TryGetList($listName)

    $fieldModified = $list.Fields.GetFieldByInternalName("Modified")
    $fieldModifiedBy = $list.Fields.GetFieldByInternalName("Editor")
    $fieldCreated = $list.Fields.GetFieldByInternalName("Created")
    $fieldContentType = $list.Fields.GetFieldByInternalName("ContentType") 


I tried to add secondary colum like this:


And got this error: Exception calling "Add" with "2" argument(s): "Value does not fall within the expected range."

Accoriding to this documentation I should be able to add a secondary column, but it does not work: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee558177(v%3doffice.15)

I don't know what I am doing wrong here. Anybody here that can point it out, or knows how this can be done?

Your Answer

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

Browse other questions tagged or ask your own question.