Created
September 4, 2014 05:43
-
-
Save sweeneyrobb/2ca905955e50ce600dd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | |
function EnsureDirectory($exportFolderPath) { | |
if (-not (Test-Path $exportFolderPath)) { | |
New-Item $exportFolderPath -Type Directory | Out-Null | |
} | |
} | |
function ExportAllWebParts($siteUrl, $pageUrl, $exportFolderPath) { | |
$web = Get-SPWeb $siteUrl | |
$wpm = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) | |
EnsureDirectory $exportFolderPath | |
$wpm.WebParts | ForEach-Object { | |
$wp = $_ | |
$wp.ExportMode="All"; | |
$exportPath = $exportFolderPath + "\" + $wp.Title + ".xml" | |
$xwTmp = new-object System.Xml.XmlTextWriter($exportPath,$null); | |
$xwTmp.Formatting = 1;#Indent | |
$wpm.ExportWebPart($wp, $xwTmp); | |
$xwTmp.Flush(); | |
$xwTmp.Close(); | |
} | |
} | |
# Example: ExportAllWebParts "http://www.contoso.com" "pages/default.aspx" "c:\temp" | |
ExportAllWebParts "{site-url}" "{rel-page-path}" "{output-dir}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment