0

I created over 50 Modern pages in one site collection, to realize they would be better housed in another site collection.

Can I copy/move these pages from one collection to another ( or copy/move the whole Site Pages library ) using PnP?

0

Try this code to move the pages

Param(
[Parameter(ParameterSetName = "Inputparameter",Position=1,Mandatory=$True)]
[String]$sharepointUrl,
[Parameter(ParameterSetName = "Inputparameter",Position=2,Mandatory=$True)]
[String]$targeturl,
[Parameter(ParameterSetName = "Inputparameter",Position=3,Mandatory=$True)]
[String]$Sourceurl,
[Parameter(ParameterSetName = "Inputparameter",Position=4,Mandatory=$True)]
[String]$SourceDocumentLib,
[Parameter(ParameterSetName = "Inputparameter",Position=4,Mandatory=$True)]
[String]$TargetDocumentLib
)
function Copy-sharepoint
{
Param(
[Parameter(Mandatory=$True)]
[String]$sharepointUrl,
[Parameter(Mandatory=$True)]
[String]$targeturl,
[Parameter(Mandatory=$True)]
[String]$Sourceurl,
[Parameter(Mandatory=$True)]
[String]$SourceDocumentLib,
[Parameter(Mandatory=$True)]
[String]$TargetDocumentLib,
[Parameter(Mandatory=$True)]
[String]$UserName,
[Parameter(Mandatory=$True)]
[String]$Password,
[Parameter(Mandatory=$True)]
[System.Management.Automation.PSCredential]$cred
)
   #create secure password
$sPassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Connect-PnPOnline -Url $Sourceurl -Credentials $cred
$Files= Find-PnPFile -List $SourceDocumentLib -Match *
Disconnect-PnPOnline
$Loginsource =$false
$webClient = New-Object System.Net.WebClient 
$webClient.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $sPassword)
$webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
$webclient.Proxy = $null
foreach($file in  $Files)
{

    If($file.Name -eq "ACE-Tech-Talks.aspx")
    {
    $pageUrl = $sharepointUrl+$file.ServerRelativeUrl
    $UniqueFileName = $file.Name
    $ByteArray=$webClient.DownloadData($pageUrl)
    $tfolderWithname= ($pageUrl -split $Sourceurl)[1]
    $tfolderwiths =($tfolderWithname -split $UniqueFileName)[0]
    $tfolderrmstr =$tfolderwiths.TrimStart("/")
    $tfolder =$tfolderrmstr.TrimEnd("/")
    $fstream = [System.IO.MemoryStream]($ByteArray)  
     If($tfolder -eq $null)
    {

        If($Loginsource -eq $false )
        {
            Connect-PnPOnline -Url $targeturl -Credentials $cred
            $Loginsource =$true
            Add-PnPFile -FileName $UniqueFileName -Folder $TargetDocumentLib -Stream $fstream
        }
        else
        {
            Add-PnPFile -FileName $UniqueFileName -Folder $TargetDocumentLib -Stream $fstream
        }
}
else
{
  If($Loginsource -eq $false )
        {
            Connect-PnPOnline -Url $targeturl -Credentials $cred
            $Loginsource =$true
            Add-PnPFile -FileName $UniqueFileName -Folder $tfolder -Stream $fstream
        }
        else
        {
            Add-PnPFile -FileName $UniqueFileName -Folder $tfolder -Stream $fstream
        }
}

    }
    }
    }
$cred=Get-Credential
$UName=$cred.UserName.ToString()
$Pass =$cred.GetNetworkCredential().Password
Copy-sharepoint -UserName $UName -Password $Pass -cred $cred -sharepointUrl $sharepointUrl -targeturl $targeturl -Sourceurl $Sourceurl -SourceDocumentLib $SourceDocumentLib -TargetDocumentLib $TargetDocumentLib
write-host "Copying of file complete"
| improve this answer | |
0
function Copy-SharePointPage
{
    param([string]$SourceSiteUrl, [System.Management.Automation.PSCredential]$SourceSiteCredential, [string]$TargetSiteUrl, [System.Management.Automation.PSCredential]$TargetSiteCredential, [string]$Page)

    $TempFile = [System.IO.Path]::GetTempFileName();

    Connect-PnPOnline -Url $SourceSiteUrl -Credentials $SourceSiteCredential;
    Export-PnPClientSidePage -Force -Identity $Page -Out $TempFile

    Connect-PnPOnline -Url $TargetSiteUrl -Credentials $TargetSiteCredential;
    Apply-PnPProvisioningTemplate -Path $TempFile
}
| improve this answer | |
0
Connect-PnPOnline -Url $sourceURL -Credential $O365Credential

Get-pnpprovisioningtemplate -out $outputXMLLocation\pages.xml -handlers PageContents -IncludeAllClientSidePages

apply-pnpprovisioningtemplate $outputXMLLocation\pages.xml

Try above commands. For more details check the Blog

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.