Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

powershell sharepoint copy file to other site collection

Add-PSSnapIn "Microsoft.SharePoint.PowerShell"

## 
#Set Static Variables 
## 

$SourceWebURL = "http://WebAppURL/sites/Area/Master" 
$SourceLibraryTitle = "Web" 
$DestinationWebURL = "http://WebAppURL/sites/OtherSiteName" 
$DestinationLibraryTitle = "Web"
$FileName = "Resources.aspx"

## 
#Begin Script 
## 

$sWeb = Get-SPWeb $SourceWebURL 
#$sList = $sWeb.Lists | ? {$_.Title -eq $SourceLibraryTitle} 
$dWeb = Get-SPWeb $DestinationWebURL 
#$dList = $dWeb.Lists | ? {$_.title -like $DestinationLibraryTitle} 

$SourceFile=$sWeb.GetFile($SourceWebURL+"/"+$SourceLibraryTitle+"/"+$FileName)
$TargetFolder = $dWeb.GetFolder($DestinationLibraryTitle)
#Copy File from the Source
$NewFile = $TargetFolder.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(),$True)

#Copy Meta-Data from Source
Foreach($Field in $SourceFile.Item.Fields)
{
    If(!$Field.ReadOnlyField)
    {
        if($NewFile.Item.Fields.ContainsField($Field.InternalName))
        {
            $NewFile.Item[$Field.InternalName] = $SourceFile.Item[$Field.InternalName]
        }
    }
}
#Update
$NewFile.Item.UpdateOverwriteVersion()

Write-host "Copied File:"$SourceFile.Name
Comment

PREVIOUS NEXT
Code Example
Shell :: install netstat windows server 
Shell :: ssh powershell 
Shell :: how to know ROS path 
Shell :: sudo windows 
Shell :: what does source command do in linux 
Shell :: install sketch for ubuntu 
Shell :: git compare two branches 
Shell :: git create a new repository 
Shell :: seeing all the installed apps i terminal 
Shell :: crosh 
Shell :: uninstall utorrent buntu 
Shell :: octave for ubuntu 20.04 
Shell :: how to change git password in git bash 
Shell :: how to check which shell 
Shell :: gradle git bash terminal weird characters 
Shell :: git remove tag from remote 
Shell :: composer add git repository 
Shell :: how to start ngrok server 
Shell :: install mongosh 
Shell :: how to restore a mongodb dump with a new name 
Shell :: linux create link to folder 
Shell :: redis install 
Shell :: multiple ssh key 
Shell :: gunicorn port 8080 
Shell :: install prisma nextjs 
Shell :: copy paste in git bash 
Shell :: create empty file command prompt cmd 
Shell :: ssh server windows 11 
Shell :: install astropy anaconda 
Shell :: open current directory 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =