Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
  [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.RecordsManagement.RecordsRepository.Records")
  [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")
  $modDate = {
      param(
          [Microsoft.SharePoint.SPListItem]$a
      )
      $a["Title"] = "NewTitle"
      $a.SystemUpdate($true)
  }
  $web = Get-SPWeb "http://mySiteCollection/"
  $item = $web.Lists["Dokument"].GetItemById(10)
  [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::BypassLocks($item,$modDate)

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.

share|improve this question

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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