0

Trying to update a sharepoint list with a powershell script but I am getting several errors like this:

Error Occurred (04/28/2018 19:13:38) with error message: Exception calling "Update" with "0" argument(s): "The file "mysite.aspx" is
checked out for editing by bla\thisuser1
Error Occurred (04/28/2018 19:13:38) with error message: Exception calling "Update" with "0" argument(s): "The file "mysite.aspx" is
checked out for editing by bla\thisuser2
Error Occurred (04/28/2018 19:13:38) with error message: Exception calling "Update" with "0" argument(s): "The file "mysite.aspx" is
checked out for editing by bla\thisuser3

etc

This is a part of the powershell script once it hits the update() statement it throws the error above:

if ($li["Topics"] -eq $null)
{
        $li["Topics"] = $si.NewTopic
        $li.Update()
}

Question: how/where can I 'clear' the checkouts on this sharepoint list? I could not find a method like UndoCheckout on the $li listitem?

1

Try SPFile.UndoCheckOut method

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.undocheckout.aspx

Based on the list type you have, either of these two should work.

$item.UndoCheckOut()
//or
$item.File.UndoCheckOut()

Also make sure run this command on files checked out. if file is not checked out command gives error.

if ($item.File.CheckOutStatus -ne "None") {
    $item.File.UndoCheckOut()
}
| improve this answer | |
  • Do you know if there is a method that works directly on the listitem? – bier hier Apr 28 '18 at 23:49
  • @bierhier I edited my answer how it helps. Also what is the type of the list? Clearly it's not a Custom List because custom lists do not have check in/out. Only Pages, document libraries have this feature. – Ergec Apr 29 '18 at 7:54
  • I think it is a document library – bier hier Apr 29 '18 at 8:11

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.