Improve Your Technology

Just another blog for techology

Reading Summary Links using Powershell

Reading Summary Links from a web part using power shell

Similar to other web parts, reading summary link web parts is always little tricky. We need to set current context before we tried to access. Below is the sample script to read all summary links from each page.

$pages = $web.Lists[“Pages”];

foreach($page in $pages.Items)


if($page -eq $null)




if ($null -eq [System.Web.HttpContext]::Current)


$sw = New-Object System.IO.StringWriter

$resp = New-Object System.Web.HttpResponse $sw

$req = New-Object System.Web.HttpRequest “”, $web.Url, “”

$htc = New-Object System.Web.HttpContext $req, $resp

$htc.Items[“HttpHandlerSPWeb”] = $web  -as [Microsoft.SharePoint.SPweb]

[System.Web.HttpContext]::Current = $htc


$webPartCollection = $page.Web.GetWebPartCollection($page.Url,[Microsoft.SharePoint.WebPartPages.Storage]::Shared)

foreach($wp in $webPartCollection)


$webpart =  $wp -as [Microsoft.SharePoint.WebPartPages.WebPart]

if ($webpart.GetType().Name -eq ‘SummaryLinkWebPart’)


Write-Output $page.url

Write-Output “Summary Links:”

$sumWP = $webpart -as [Microsoft.SharePoint.Publishing.WebControls.SummaryLinkWebPart]


foreach ($summarylink in $sumWP.SummaryLinkValue.SummaryLinks)


Write-Output $summarylink.LinkUrl






October 12, 2012 - Posted by | Power Shell, Reading Summary Links, SharePoint, SharePoint 2010 | ,

1 Comment »

  1. thnx for your code.
    may i know how to set the target audience for this summarylinks web part.
    help is appreciated!

    Comment by SaMolPP | January 5, 2015 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: