Description
Reporting an Issue
While setting new text value to the Text Out of the box webpart(using Set-PnPPageTextPart cmdlet) and also while updating the webpart properties back to other oob/custom webpart (using Set-PnPPageWebPart cmdlet) programmatically through powershell, Additional banner is getting appended along with the existing banner in the updated page.
Expected behavior
Set-PnPPageTextPart and Set-PnPPageWebPart cmdlets should set the new data only on the text out of the box webpart and custom/oob webpart respectively. It should not append any new banner in the updated page after setting the text/webpart properties.
Actual behavior
Set-PnPPageTextPart and Set-PnPPageWebPart cmdlets are appending new banner after setting the new text or webpart properties for text oob/custom webparts which is weird and strange.
Ideally It should not have duplicate banner in the updated page after setting new text content in webpart.
It should update only the new text content in the oob/custom webpart.
Steps to reproduce behavior
#Note: Please create a new Modern Page and add text OOB component and add some content in it and publish the page.
Then utilize the same page name below. Please use other parameters like credentials if you are unable to connect to Sharepoint Online.
Code Snippet
$siteUrl = ""
$appId = ""
$appSecret = ""
Connect to SharePoint Online
$pageName = "<Any new page where a simple Text OOB webpart is added in a new section after the default banner section , Eg : Page-Text-Webpart.aspx>"
try {
#Main Function
$page = Get-PnPPage -Identity "$($pageName)" -Connection $global:pnpConnection
foreach ($control in $page.Controls) {
try {
#region Set Webpart Properties according to the language
$updatedText = "Iam fine"
#$updatedText = "How are you?"
#$updatedText = "Hope your family is well"
# ConvertTo-Html -InputObject $control | Out-Null
# Write-Host $($control.ControlType)
if($control.Type.ToString().IndexOf("PageText") -ge 0){
$control.ToHtml($control.ControlType) | Out-Null
Set-PnPPageTextPart -Page $pageName -InstanceId $control.InstanceId -Text $updatedText -Connection $global:pnpConnection
}
elseif ($control.WebPartId -eq "<AnyGuid>"){
$control.ToHtml($control.ControlType) | Out-Null
Set-PnPPageWebPart -Page $pageName -Identity $control.InstanceId -PropertiesJson $control.JsonWebPartData -Connection $global:pnpConnection
}
}
catch {
Write-Host $_
$pageConversionLogCount.Status = "Error"
}
}
}
catch {
Write-Host "[ERROR]:
# log -content "[ERROR]: $ at $($_.InvocationInfo.ScriptLineNumber) LineNumber In Main Function (Triggering Point)" -path $logParentFilePath
$parentLogCount.Status = "Error"
}
$global:pnpConnection = $null
Page before updating new text in Text OOB webpart :
Page after updating new text in Text OOB webpart :
What is the version of the Cmdlet module you are running?
ModuleType Version Pre-release Name PSEdition
Manifest 2.1.1 PnP.PowerShell Desk
Which operating system/environment are you running PnP PowerShell on?
- Windows
##Powershell Version - 7.4.5
##node version - v16.17.1
##npm version - 8.15.0
Please suggest a resolution for this issue.
Note : I'm able to reproduce the same issue by using latest PnP Version - 2.12.0, Kindly check and update.
Thank you,
Sreekrishna Sai