Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Get-WebParts($fileName){
$web = Get-PnPWeb
$serverRelativePageUrl = $web.ServerRelativeUrl + "/" + $librarySitePages + "/" + $fileName
#Get all web parts
$webParts = Get-PnPWebPart -ServerRelativePageUrl $serverRelativePageUrl
$count = 0
foreach($webPart in $webParts){
$count++
$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