Created
June 24, 2014 16:16
-
-
Save mirontoli/288f5aedd9a0760e4077 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
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