I am trying to update a Sharepoint 2010 record using ByPassLock method in Powershell.
I am using below code

  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
  $modDate = {
      $a["Title"] = "NewTitle"
  $web = Get-SPWeb "http://mySiteCollection/"
  $item = $web.Lists["Dokument"].GetItemById(10)

After execution of the script i get below error

Exception calling "BypassLocks" with "2" argument(s): "Attempted to perform an unauthorized operation."
+ [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::BypassLocks <<<< ($item,$modDate)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

I running this script as administrator and have site collection administrator access on the site. I removed item update part but still it is not working.

1 Answer 1


It worked when I executed under token of the System Account for the site collection.

#Get Systrem User ID
$sysId = $web.Site.SystemAccount.ID
$sysuser = $web.AllUsers[$sysId]
$token = $sysuser.Token

#Create New Site Object under Token of System Account for the Site Collection
$newSiteObject = New-Object Microsoft.SharePoint.SPSite($web.Url, $token)
$newWebObject = $newSiteObject.OpenWeb()
$item = $newWebObject.GetListItem($fileurl)        
[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::BypassLocks($item, $byPassMethodName)        

Your Answer

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

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