域\用户的文档库列更新错误 [英] Document Library column update error for domain\users

查看:91
本文介绍了域\用户的文档库列更新错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的Power Shell代码来更新文档库列.

I have below power shell code to update document library column.

add-pssnapin microsoft.sharepoint.powershell -EA 0
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

函数GetFiles($ folder)
{
  写主机"+" $ folder.Name

    foreach($ folder.Files中的$ file)
     {    
      写主机"t" $ file.Name
     
$ file.Item [原始文件名"] = $ file.Name
  $ file.Item.Update()
    }
    
    foreach($ folder.SubFolders中的$ SubFolder)
       {
           if($ SubFolder.Name -ne"Forms")
           { 
              写主机"t" -NoNewline
                 GetFiles($ Subfolder)
                
            }
        }

 }

$ url =" http://docportal2016:11/acc/"
$ site =新对象Microsoft.SharePoint.SPSite($ url)
$ SPWeb = $ site.OpenWeb()
$ SPList = $ SPWeb.Lists ["Project"]
if((($ SPList.BaseType -eq" DocumentLibrary")-and($ SPList.Hidden -eq $ false))
{
 写入主机`t" $ SPList.RootFolder
if($ SPList.RootFolder.Name -eq" Project")
{
GetFiles($ SPList.RootFolder)
}
}

add-pssnapin microsoft.sharepoint.powershell -EA 0
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function GetFiles($folder)
{
   Write-Host "+"$folder.Name

    foreach($file in $folder.Files)
    {    
        Write-Host "`t" $file.Name
     
$file.Item["Original File Name"]=$file.Name
 $file.Item.Update()
    }
    
     foreach ($SubFolder in $folder.SubFolders)
        {
            if($SubFolder.Name -ne "Forms")
            {  
                Write-Host "`t" -NoNewline
                GetFiles($Subfolder)
                
            }
        }

 }

$url = "http://docportal2016:11/acc/"
$site= new-Object Microsoft.SharePoint.SPSite($url )
$SPWeb = $site.OpenWeb()
$SPList = $SPWeb.Lists["Project"]
if(($SPList.BaseType -eq "DocumentLibrary") -and ($SPList.Hidden -eq $false))
{
 Write-Host "`t" $SPList.RootFolder
if($SPList.RootFolder.Name -eq "Project")
{
GetFiles($SPList.RootFolder)
}
}

我有一个名为原始文件名"的列.我的脚本会将文件名更新到此列中.实际上,我的脚本可以与"sharepoint \ system"系统正常工作.用户.如果文档是通过域\用户名"修改的,然后是原始" 文件名"正在正确更新.如果该文档被任何其他域用户使用,那么我们将在Power Shell中遇到以下错误.

I have column called "Original File Name". My script will update the file name in to this column. Actually my script is working fine with "sharepoint\system" user. If the document is modified by "domain\username" then the "Original File Name"is updating properly . If the document is used by any other domain user then we are getting below error in power shell.

异常调用更新";带有"0"参数:文件Project/Lse Doc/Mail Files/74237.pdf已由i:0#.w | domain \ username于2017年12月17日12:02:14 +0530修改."
在E:\ SharePoint \ SharePoint \ UpdateOriginalFileNameDocLib.ps1:13 char:2
+  $ file.Item.Update()
+  ~~~~~~~~~~~~~~~~~~
    + CategoryInfo         :未指定:(:) [],MethodInvocationException
    + FullyQualifiedErrorId:SPException

Exception calling "Update" with "0" argument(s): "The file Project/Lse Doc/Mail Files/74237.pdf has been modified by i:0#.w|domain\username on 17 Dec 2017 12:02:14 +0530."
At E:\SharePoint\SharePoint\UpdateOriginalFileNameDocLib.ps1:13 char:2
+  $file.Item.Update()
+  ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SPException

感谢&问候

Poomani Sankaran

Poomani Sankaran

推荐答案

尝试使用SPListItem.SystemUpdate(false)方法来更新脚本中的列值,如下所示:

Try to use SPListItem.SystemUpdate(false) method to update the column value in the script like below:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function GetFiles(


文件夹) { 写入主机"+"
folder) { Write-Host "+"


folder.Name foreach(
folder.Name foreach(


这篇关于域\用户的文档库列更新错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆