I am using below script to iterate through each folder/file in document library.

$source = "http://sitecollection/sites/site/subsite"
$dest = "http://sitecollection/sites/site/subsitearchive"

$sourceLibrary = (Get-SPWeb $source).Folders["Test"]
$destLibrary = (Get-SPWeb $dest).Folders["Test"]
$destFiles = $destLibrary.Files
foreach ($file in $sourceLibrary.Files)
    $curFile = $file.OpenBinary()
    $destURL = $destFiles.Folder.Url + "/" + $file.Name
    $destFiles.Add($destURL, $curFile, $true)

However, I am getting error: Cannot find an SPWeb object with Id or URL


Code seems legit, check permissions for user running PS - it should have access to both sites eventually run as admin. But check it also.

you can also replace line

$destURL = $destFiles.Folder.Url + "/" + $file.Name


$destURL = $destLibrary.Url + "/" + $file.Name

But it's only a cosmetic upgrade

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.