56 lines
1.3 KiB
Markdown
56 lines
1.3 KiB
Markdown
![]() |
Copy File from one SC to other
|
|||
|
|
|||
|
Sonntag, 22. Dezember 2019
|
|||
|
|
|||
|
12:35
|
|||
|
|
|||
|
|
|||
|
|
|||
|
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
|
|||
|
|
|||
|
|
|||
|
|
|||
|
Aus \<<https://stackoverflow.com/questions/51597082/sharepoint-2013-powershell-copy-file-from-one-site-collection-to-another/51604552>\>
|
|||
|
|
|||
|
|