1

I'm trying to write a script that will unarchive a list item from a sql database archive. The data is going back to the same list that it was in originally so the fields are all matched up. I'd like to be able to put the item back in with the same ID, so lookups in other lists aren't broken. I'd done some research and it seems that others have had success by setting the ID field to readonlyfield = false but I haven't been able to manage it.

  $lstStudents = $web.Lists["Students"]
  $lstStudents.Fields["ID"].ReadonlyField = $false
  $lstStudents.update()

Completes without any errors, but the ID of the item when I run the rest of the script doesn't keep the desired ID. Furthermore, when I check the value of $lstStudents.Fields["ID"].ReadonlyField it still says true.

Any ideas appreciated.

1

I'm pretty certain that you cannot change the ID. It is auto assigned. If you want to maintain your own ID, you will need to add a custom column to the list.

That said, there's sample C# code here (List item with specific ID value) that says you can update the ID field from the list.Fields[SPBuiltInFieldId.ID] property.

  • I've been playing around with this code and it seems like I can set an arbitrary ID in a C# console application but not in Powershell. In fact, if I run the code you linked to but comment out the line "list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = true;" and look at the $list["ID"] field, it still shows as ReadOnlyField = true. I'm guessing that somehow the SPBuiltInFieldId.ID is somehow different from indexing the fields. It's very weird. Still looking for a way to access [SPBuiltInFieldId.ID] from powershell – steam23 Nov 16 '18 at 14:50

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.