Forum Discussion
fstorer
Mar 27, 2020Brass Contributor
SharePoint Online - Copy site pages between site collections - is that possible?
Hello everyone, I have been asked to move some site pages from a Microsoft Team to another Team. In the modern look of SharePoint Online I can select the page (example1.aspx) and when clicking on...
Sheldon-Faria
Nov 26, 2020Copper Contributor
fstorer Hi, for anyone looking for a solution this might help:
Import-Module SharePointPnPPowerShellOnline
#Source and Target Sites
$tenant = "tenant";
$SourceUrl="https://$tenant.sharepoint.com/sites/sourceSite"
$targetRelativeLibraryUrl="/sites/marketing/SitePages"
#SPO Connection
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString
$adminUPN = "admin@australia.com.au"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUPN, $AdminPassword
Connect-PnPOnline -Url $SourceUrl -Credentials $cred
#Connect-PnPOnline -Url $SourceUrl -UseWebLogin
$ServerRelativeUrl=(Get-PnPWeb).ServerRelativeUrl
#Get all source pages
$pages = Get-PnPListItem -List sitepages
Foreach($page in $pages){
$pageName = $page.FieldValues["FileLeafRef"]
#if($pageName -like "Migrated*"){ #OPTIONAL FILTER
#Write-Host $pageName
$file = Get-PnPFile -Url "$ServerRelativeUrl/sitePages/$pageName"
$fileServerRelativeUrl = Get-PnPProperty -ClientObject $file -Property "ServerRelativeUrl"
#Start the move
Move-PnPFile -ServerRelativeUrl $fileServerRelativeUrl -TargetServerRelativeLibrary $targetRelativeLibraryUrl -Force -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination
#}
}
JORGE_CORREA_MUOZ
Aug 19, 2022Copper Contributor
Thanks a lot, Do you can tell me, how I can create a log file for this process?