Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function Get-WebParts($fileName){
$pageFile = $librarySitePages + "/" + $fileName
$web = Get-PnPWeb
$serverRelativePageUrl = $web.ServerRelativeUrl + $pageFile
#Get all web parts
$webParts = Get-PnPWebPart -ServerRelativePageUrl $serverRelativePageUrl
$count = 0
foreach($webPart in $webParts){
$xml = Get-PnPWebPartXml -ServerRelativePageUrl $serverRelativePageUrl -Identity $webPart.Id
$newFileName = "webpart_" + $fileName + "_" + $count.ToString() + ".xml"
#Save file to locale
Set-Content -Path $newFileName $xml -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.