使用Powershell中的Bypasslock方法更新记录时出错

时间:2014-05-22 12:40:06

标签: powershell sharepoint

我正在尝试使用Powershell中的ByPassLock方法更新Sharepoint 2010记录 我使用下面的代码

  [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)

执行脚本后,我得到以下错误

使用“2”参数调用“BypassLocks”的异常:“尝试执行未经授权的操作。”
+ [Microsoft.Office.RecordsManagement.RecordsRepository.Records] :: BypassLocks<<<< ($项目,$创建ModDate)
+ CategoryInfo:NotSpecified:(:) [],MethodInvocationException
+ FullyQualifiedErrorId:DotNetMethodException



我以管理员身份运行此脚本,并在站点上拥有网站集管理员访问权限。我删除了项目更新部分但仍然无法正常工作。
有人可以帮助我吗

1 个答案:

答案 0 :(得分:0)

当我在网站集的系统帐户的令牌下执行时,它工作正常。

    #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)