2012-07-17 145 views
4

我有一个需要从一个文档库移到〜10,000个文件到另一个相同的网站收藏。我相信powershell是做这件事的最好方式。移动文档库之间的文件在同一网站集

我发现了以下文章:http://blog.isaacblum.com/2011/10/04/spfilecollection-class-copy-files-to-another-document-library/#respond,它提出了一种方法,但我不确定如何修改此脚本(我正在使用此项目首次接触Powershell)。

我尝试以下无济于事:

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

$org = "hhttp://farm/sitecollection/Document Library Source/Forms/AllItems.aspx" 
$dest = "hhttp://farm/sitecollection/Document Library Destination/Forms/AllItems.aspx" 

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

是否有这样做的另一种方式吗?请注意,我用MOSS2007和PowerShell 2.0,而不是SharePoint 2010的

更新/半答:

按x0n的帖子下面这不是在SharePoint 2007(2010只)的支持。我recevied以下建议这个线程,这是有关外,并应帮助别人的未来:

不幸的是SharePoint 2010中的命令行管理程序(这是PowerShell的 管理单元和相关的cmdlet)不与MOSS 2007兼容 有没有为 版本的SharePoint的可直接从微软的cmdlet。这也就意味着,你仍然可以使用 PowerShell和MOSS 2007,但你要么将不得不编写直接使用STSADM或SharePoint对象模型 自己的cmdlet,或者你将不得不使用MOSS 2007兼容的cmdlet 来自第三方。我建议查看Gary Lapointe的博客 许多优秀的PowerShell cmdlet,用于MOSS 2007 (http://blog.falchionconsulting.com/),或者人们上传 cmdlet的地方,如CodePlex.com,TechNet脚本库, POSHCode.org,或http://get-spscripts.com/

回答

4

我并不感到惊讶,你无处可去:Microsoft.SharePoint.PowerShell管理单元仅适用于SharePoint 2010,并且不适用于SharePoint 2007服务器。

坦率地说,要做到这一点最简单的方法就是打开IE浏览器,定位到源文档库并打开“资源管理器视图”。选择所有文件,然后复制(ctrl + c)。打开另一个IE窗口并为目标文档库执行相同的操作并粘贴(ctrl + v)。

如果无法在资源管理器视图中打开,请确保您用于复制/粘贴的机器运行“WebClient”服务。如果您运行的是Windows 2008 R2,除非您决定添加“桌面体验”功能,否则此服务不可用。这是一个更容易找到在Windows 7机器代替,这将有WebClient服务

更新(但要确保它运行。):

这就是说,你的剧本大概是80%左右那里并不真的需要2010年的管理单元。我现在不能测试此权利(对不起),但它应该是约99%的正确:

[reflection.assembly]::loadwithpartialname("microsoft.sharepoint") > $null 

$org = "http://farm/sitecollection/sourcedoclib" 
$dest = "http://farm/sitecollection/targetdoclib" 

$site = new-object microsoft.sharepoint.spsite $org 
$web = $site.openweb() 

$srcLibrary = $web.Lists["sourcedoclib"] 
$destLibrary = $web.Lists["targetdoclib"] 

$destFiles = $destLibrary.Folders["Archived"] 

foreach ($item in $srcLibrary.Items) 
{ 
    if ($item.File) { 
     $curFile = $item.file.OpenBinary() 
     $destURL = $destFiles.Folder.Url + "/" + $item.file.Name 
     $destFiles.Add($destURL, $curFile, $true) 
    } 
} 

好运。

+0

这就是我们以前的做法,但不幸的是,这是一个反复出现的过程,可能在本月底之前跨越30多个文档库 - 是否有一个用于MOSS的PowerShell库,可用于完成上述操作? – Codingo 2012-07-17 01:44:31

+0

无论如何,您不应该修改脚本_that_以使其在2007年运行。让我看看它。 – x0n 2012-07-17 02:08:58

+0

我试图实现这一点,但我收到以下每个文件在库(它不动),任何想法?错误是:您无法在空值表达式上调用方法。 At line:20 char:23 + $ destFiles.Add <<<<($ destURL,$ curFile,$ true) + CategoryInfo:InvalidOperation:(Add:String)[],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull – Codingo 2012-07-17 03:38:20

相关问题