【问题标题】:migrate document with its meta data from one document library to a folder将文档及其元数据从一个文档库迁移到文件夹
【发布时间】:2014-04-28 21:45:21
【问题描述】:

我是 sharepoint 的初学者,特别是 powershell。 我正在尝试将文档库的所有文档从一个站点移动到文件夹内的另一个站点。但我可以只复制来自内容类型的文件而不是元数据!

 $PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue                 Out-Null
    clear


$org = "http://'YYYYY'/sites/XXXX"
$dest = "http://'YYYYY'/sites/XXXX/Subsite"

$orgLibrary = (Get-SPWeb $org).Folders["newdoc1"]
$destLibrary = (Get-SPWeb $dest).Folders["newdoc2"].SubFolders["folder1"]
$destFiles = $destLibrary.Files
foreach ($file in $orgLibrary.Files)
{
    $curFile = $file.OpenBinary()
    $destURL = $destFiles.Folder.Url + "/" + $file.Name
    $destFiles.Add($destURL, $curFile, $true)
}

【问题讨论】:

    标签: sharepoint powershell metadata


    【解决方案1】:

    这里的这个就是这样做的。除了修改日期和创建日期外,其他所有字段都带过来了。

    $web = Get-SPWeb "http://sharepointed.com/"
    $list = $web.Lists["Shared Documents"]
    
    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $spQuery.ViewAttributes = "Scope='Recursive'";
    $spQuery.RowLimit = 2000
    $caml = '<Where><Lt><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2014-01-01T04:06:45Z</Value></Lt></Where> '
    $spQuery.Query = $caml 
    
    do
    {
        $listItems = $list.GetItems($spQuery)
        $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
        $listTotal = $listItems.Count
    
        for ($x=$listTotal-1;$x -ge 0; $x--)
        { 
            try
                {  
                    $listItems[$x].CopyTo("http://sharepoint/Docs/Documents/"+ $listItems[$x].name) 
                    Write-Host("DELETED: " + $listItems[$x].name)
                    $listItems[$x].Recycle() 
                }
            catch
                {
                Write-Host $_.Exception.ToString()
                }
        }
    }
    while ($spQuery.ListItemCollectionPosition -ne $null)
    

    通过Ian

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      相关资源
      最近更新 更多