Skip to content

Instantly share code, notes, and snippets.

@Vintaurus
Last active June 25, 2020 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vintaurus/80a5aa7d83a459bb42ee78f97840d75c to your computer and use it in GitHub Desktop.
Save Vintaurus/80a5aa7d83a459bb42ee78f97840d75c to your computer and use it in GitHub Desktop.
function Get-WebParts($fileName){
$pageFile = $librarySitePages + "/" + $fileName
$web = Get-PnPWeb
$serverRelativePageUrl = $web.ServerRelativeUrl + $pageFile
$serverRelativePageUrl
#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