I recently had a change request against a SharePoint Forms Library I had created a few years ago – the request was to adjust the permissions so that form submitters could see only the forms that they’ve submitted (and not others).
This is a generally straightforward action on new libraries: enable ” Require content approval for submitted items?”, and change “Who should see draft items in this document library?” to “
However, enabling these settings seems to have caused the items that already existed to have an Approval Status of “Approved, ” despite a pending Approval workflow. This caused the undesired effect of allowing users who do not hold the “Approve” permission level to access a previous version of items still in the approval workflow.
I needed to reject previous versions of forms where the current version had not yet been approved. On lots of items.
I found numerous examples from google how to use PowerShell to set the Approval Status of list items; however, nearly every example dealt with only the current version of a list item – making no mention of altering the approval status of previous versions of list items.
Additionally, I found a few posts attempting to manipulate attributes for previous versions; the responses for each of these inquires were varied:
- “you can’t – history is read-only,”
- “you can migrate the documents to a new list, and re-build the history”
- “you can delete the old versions”
I even found a mega-thread on TechNet how to “List and Delete List Item Versions using PowerShell,” and a “Complete Guide to Getting and Setting Fields Using PowerShell”
None of these options accomplished what I was seeking: to simply remove the approval on previous versions.
Finally, I resorted to simply poking at the objects from PowerShell (never under-estimate the power of Get-Member to explore objects) Attempting to modify the properties on a previous version would yeild the error message “Unable to index into an object of type Microsoft.SharePoint.SPListItemVersion” (Link)
Ok – different approach: I know my desired action is feasible via the UI for single list items:
So, I opened Chrome developer tools and captured the command sent when clicking “Reject this version”: A POST to “/_layouts/versions.aspx” with the ItemID, and an “op” value of “TakeOffline”. A quick google search revealed a server-side object model equilavent: Microsoft.SharePoint.SPFile.TakeOffline
My solution: invoke SPListItem.File.TakeOffline() for every file which is currently pending and has a previously approved version: