s
Here is my code for copy file from on site to other site But
here is errror
You cannot call a method on a null-valued expression.
At line:5 char:40
+ $dFile = $dList.RootFolder.File.Add <<<< ($RootItem.Name, $sBytes, $true)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:22 char:18
+ $dFile.Update <<<< ()
+ CategoryInfo : InvalidOperation: (Update:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
$SourceWebURL = "http://portal-dev:45106/personal/test"
#SoureLibraryTitle is the title of the Source Library where documents reside
$SourceLibraryTitle = "Shared Documents"
$DestinationWebURL = "http://portal-dev/IT/test/backup"
#DestinationLibraryTitle is the title of the destionation library in which you want to store your files
$DestinationLibraryTitle = "mysitebackup"
write-host $DestinationLibraryTitle
$sWeb = Get-SPWeb $SourceWebURL
$sList = $sWeb.Lists | ? {$_.Title -eq $SourceLibraryTitle}
$dWeb = Get-SPWeb $DestinationWebURL
#Retrieve the source list using the parameter provided
$dList = $dWeb.Lists | ? {$_.title.ToLower() -like $DestinationLibraryTitle}
#Retrieve all folders in the source list. This used to maintain the folder structure in source and destination libraries. This excludes the root folder
$AllFolders = $sList.Folders
#Retrieve the root folder in the source list.
$RootFolder = $sList.RootFolder
#Return all files that exist directly in the root of the library
$RootItems = $RootFolder.files
foreach($RootItem in $RootItems)
{
$sBytes = $RootItem.OpenBinary()
Write-host $RootItem
$dFile = $dList.RootFolder.File.Add($RootItem.Name, $sBytes, $true)
$AllFields = $RootItem.Item.Fields | ? {!($_.sealed)}
foreach($Field in $AllFields)
{
if($RootItem.Properties[$Field.Title])
{
if(!($dFile.Properties[$Field.title]))
{
$dFile.AddProperty($Field.Title, $RootItem.Properties[$Field.Title])
}
else
{
#If the property already exists, set the value on the destination item to the same value as it was in the source item.
$dFile.Properties[$Field.Title] = $RootItem.Properties[$Field.Title]
}
}
}
$dFile.Update()
}
You cannot call a method on a null-valued expression.
At line:5 char:40
+ $dFile = $dList.RootFolder.File.Add <<<< ($RootItem.Name, $sBytes, $true)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:22 char:18
+ $dFile.Update <<<< ()
+ CategoryInfo : InvalidOperation: (Update:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull