📜  powershell sharepoint 将文件复制到其他网站集 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:51:28.604000             🧑  作者: Mango

代码示例1
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