$credentials = Get-Credential Connect-PnPOnline -Url $sourceUrl -CreateDrive -Credentials $credentials
Write-Host "Downloading WebPart Xml.." -ForegroundColor Cyan $xml = "<WebParts>" Get-PnPWebPart -ServerRelativePageUrl $FileServerRelativeURL -Web $webPath | ForEach-Object { $xml += Get-PnPWebPartXml -ServerRelativePageUrl $FileServerRelativeURL -Web $webPath -Identity $_.Id } $Xml = $xml.replace('<?xml version="1.0" encoding="utf-16"?>','') $xml += "</WebParts>" $file = $XmlFilelocation + "\webparts.xml"; Set-Content -Path $file $xml
$credentials = Get-Credential Connect-PnPOnline -Url $targetUrl -CreateDrive -Credentials $credentials
$xmlFilePath = $path + "\webparts.xml" $content = Get-Content $xmlFilePath [xml]$xmlContent = $content.replace($OldSubSiteName,$NewSubSiteName)
Write-Host $page Write-Host "Checking out "$page -ForegroundColor Gray Set-PnPFileCheckedOut -Url $page -Web $subSiteRelativePath
Write-Host "Adding Webparts" -ForegroundColor Gray $xmlContent.WebParts.WebPart | ForEach-Object { Remove-PnpWebPart -ServerRelativePageUrl $page -Web $subSiteRelativePath -Title $_.Title Add-PnPWebPartToWebPartPage -Xml $_.OuterXml -ZoneId $_.ZoneId -ServerRelativePageUrl $page -ZoneIndex 0 } Write-Host "Added Webparts" -ForegroundColor Green
Set-PnPFileCheckedIn -Url $page -Web $subSiteRelativePath -CheckinType MajorCheckIn -Comment "Updated webparts" Write-Host "Checked In "$page -ForegroundColor Gray