Public paste
Undefined
By: Guest | Date: Sep 25 2014 09:13 | Format: None | Expires: never | Size: 1.01 KB | Hits: 858

  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  2.  
  3.  
  4.  $url = "http://adeb.crayondev.dev/";
  5.  $page = "Sider\nyhetsarkiv.aspx";
  6.  
  7.  $exportFolderPath = "C:\GIT\";
  8.  
  9. function ExportAllWebParts($siteUrl,$pageUrl,$exportFolderPath)
  10.  {
  11.  $web = Get-SPWeb $url
  12.  $file = $web.GetFile($page);
  13.  #$file.CheckIn($false);
  14.  $file.CheckOut();
  15.  
  16.  $wpm = $web.GetLimitedWebPartManager($file.Url, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
  17.  $i=0;
  18.  foreach($wp in $wpm.WebParts)
  19.  {
  20.  $i++;
  21.     Write-Host "Exporting " $wp.Title;
  22.     $wp.ExportMode="All";
  23.     $exportPath = $($exportFolderPath + "\" + $wp.Title.Replace(":","_") + $i + ".xml");
  24.     $xwTmp = new-object System.Xml.XmlTextWriter($exportPath,$null);
  25.     $xwTmp.Formatting = 1;#Indent
  26.     $wpm.ExportWebPart($wp, $xwTmp);
  27.     $xwTmp.Flush();
  28.     $xwTmp.Close();
  29.     Start-Process "notepad.exe " $exportPath;
  30.  }
  31.  $file.CheckIn($false);
  32. }
  33.  
  34.  
  35.  ExportAllWebParts $url $page $exportFolderPath;