2

I'm using OneDrive (office 365 account) as a cloud backup, and I got a problem with the versioning system as for big files (outlook .ost and .pst mainly) it keeps generating new versions for the file with each synchronization thus reaching easily the storage account limit.

I wasn't able to find a way to limit the (Major) versioning number under 100 (do you have any suggestion other than Microsoft article)

Anyway, I came across this wonderful solution/code to control the number of versions of a file/folder and I adapted it for my scenario.

It works absolutely fine, BUT when the file is big (let say > 1GB), ALWAYS get this error trying to get its versions.

Operation is not valid due to the current state of the object.

No matter how I access the file versions it gets an error. I tried several approaches:

  • $File.Versions
  • Get-PnPProperty -ClientObject $File -Property Versions
  • Using context...
   $Ctx = Get-PnPContext 
   $Ctx.RequestTimeOut = -1
   $Ctx.Load($File.Versions)  
   $Ctx.ExecuteQuery()

But I can't get it right. I'm currently using PnP PowerShell .NET Core version, but the same happens with previous versions.

enter image description here

And it has versions... enter image description here

Note: I can still manage/delete the versions by web interface, but not by code

1 Answer 1

1

Since no one seems to know a solution, I ended up with a workaround for my big files history problem.

Surprisingly, although the big files versions can't be reached, they can be completely erased.

write-host -f Cyan "`t`tDeleting ALL versions..." -NoNewline
$File.Versions.DeleteAll()
try {
      Invoke-PnPQuery
      Write-Host -f Green " DELETED"
}
catch {
      Write-Host -f Red " ERROR!!!"
}

Keeping the onedrive account use at bay.

Note: I still would apreciate a more neat solution regarding keeping small number of versions.

3
  • I'm having same problem, although I am using CSOM commands. Not even '...DeleteAll()' works for me. Files bigger than ~1.2GB always return this error message, although upload of new version works without a problem. It's been same time since you posted this answer, have you found new ways how to do it ?
    – mauek unak
    Feb 3, 2021 at 15:33
  • 1
    Sorry @mauekunak , nothing new under the sun ... same old, same old. I have a try - catch to get the file versions. If it fails, I asume the file is a large one and then, with this above piece of code, "reset" it's versions history. It is working for me using github.com/pnp/powershell Feb 4, 2021 at 17:35
  • so after further investigation I found out that it was problem with permissions of file(s) on SharePoint. The error message is not very intuitive.
    – mauek unak
    Feb 4, 2021 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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