【问题标题】:Error while updating a record using Bypasslock method in Powershell在 Powershell 中使用 Bypasslock 方法更新记录时出错
【发布时间】:2014-05-22 12:40:05
【问题描述】:

我正在尝试使用 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 + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException



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

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    当我在网站集的系统帐户令牌下执行时,它起作用了。

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

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多