Copying Files Between Document Libraries using PowerShell

If your requirement demands to copy SharePoint files from one document library to another document library, you can use the following Power Shell command to move over the documents with in a same site collection.
 
$source = "http://mysite/sample/Source"
$Destination = "http://mysite/sample/Destination
$sourceList = Get-SPList $source
$sourceFieldColumns = $sourceList.Fields;
$sourceItems = $sourceList.GetItems(); 
$DestinationList = Get-SPList $destination 
foreach($spListItem in $sourceItems) {
 $DestSPListItem = $DestinationList.RootFolder.Files.Add($spListItem.Name, $spListItem.File.OpenBinary()).Item;
 
foreach($spField in $sourceFieldColumns{
 if ($spField.ReadOnlyField -ne $True) {
 $DestSPListItem[$($spField.InternalName)] = $spListItem[$($spField.InternalName)];
 }
 }
 $DestSPListItem.Update();
}
 
The key here is make sure that you set the internal name otherwise the copy process doesn't occur
Ebook Download
View all
Learn
View all