Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Created June 24, 2014 16:16
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 mirontoli/288f5aedd9a0760e4077 to your computer and use it in GitHub Desktop.
Save mirontoli/288f5aedd9a0760e4077 to your computer and use it in GitHub Desktop.
function Export-WebPart {
<#
.Synopsis
Short description
.DESCRIPTION
Does not work, it redirects
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
[CmdletBinding()]
Param
([Parameter(Mandatory=$true)]$PageUrl,
[Parameter(Mandatory=$true)]$WebPartTitle)
asnp *share*
$site = new-object microsoft.sharepoint.spsite $PageUrl
$web = $site.OpenWeb()
$wpManager = $web.GetLimitedWebPartManager($PageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $wpManager.WebParts | ? { $_.Title -eq $WebPartTitle }
if (-not $webpart) { throw "No webpart with the provided Title was found" }
$url = "$($web.Url)/_vti_bin/exportwp.aspx?pageurl=$PageUrl&guidstring=$($webpart.ID)"
$wc = new-object net.webclient
$wc.UseDefaultCredentials = $true
$content = $wc.DownloadString($url)
# another alternative
$IE = New-Object -com internetexplorer.application;
$IE.visible = $true;
$IE.navigate($url);
#another alternative
[net.httpwebrequest]$s = [net.webrequest]::Create($url)
$s.AllowAutoRedirect = $true
$s.UseDefaultCredentials = $true
$response = $s.GetResponse()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment