Moving files between document libraries to the same site collection

I need to move ~ 10,000 files from one document library to another in the same site collection. I believe powershell is the best tool for this.

I found the following article: http://blog.isaacblum.com/2011/10/04/spfilecollection-class-copy-files-to-another-document-library/#respond , which suggested a tool for this, however I'm not sure how to adapt this script (I get my first introduction to Powershell with this project).

I tried the following to no avail:

$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) } 

Is there an alternative way to do this? Note that I am using MOSS2007 and Powershell 2.0, not SharePoint 2010.

Update / Semi-Answer:

According to x0n post below, this is not supported in SharePoint 2007 (2010 only). I received the following advice outside of this topic, which is relevant and should help others in the future:

Unfortunately, the SharePoint 2010 Management Shell (these are PowerShell snap-ins and their associated cmdlets) is not compatible with MOSS 2007 and there are no cmdlets available directly from Microsoft for this version of SharePoint. This means that you can still use PowerShell with MOSS 2007, but you will either have to write your own cmdlets that use STSADM or the SharePoint object model directly, or you will have to use MOSS 2007-compatible third-party cmdlets. I would suggest checking out the Gary Lapointe blog for a large number of PowerShell cmdlets for MOSS 2007 (http://blog.falchionconsulting.com/) or where people download cmdlets such as CodePlex.com, TechNet repository scriptPOSHCode.org, or http: //get-spscripts.com/ .

+4
source share
1 answer

I'm not surprised you are not getting anything: Snapin for Microsoft.SharePoint.PowerShell is for SharePoint 2010 only and is not available on the SharePoint 2007 server.

Frankly, the easiest way to do this is to open Internet Explorer, go to the original document library and open the "explorer". Select all documents and copy (ctrl + c). Open another IE window and do the same for the target document library and paste (ctrl + v).

If it does not open in the Explorer view, make sure that the WebClient service is running on the computer that you use to copy / paste. If you are using Windows 2008 R2, this service is not available unless you decide to add the desktop feature. It's much easier to find a Windows 7 machine that will have a WebClient service (but be sure to make sure it works.)

Update:

However, your script is probably around 80%, and this 2010 snapin is not really needed. I cannot verify this right now (sorry), but it should be about 99% correct:

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

Good luck.

+4
source

All Articles