Improve Your Technology

Just another blog for techology

Listing all Sites and Webs having a List

When I was working for one of the customer I come across a requirement to update a list properties at all sites and sub-sites. Before updating list details I would like to know all the webs having the list. For this requirement I thought of writing small windows program to generate a CSV file with all the data. But later realized we have PowerShell to do all the things that we can do with a console application. Then I have written below script. After completion of writing, I realized the smartness of PowerShell. It reduced my turnaround time.

$date = Get-Date

$outFile = “.\ListDetails.csv”

$webappurl = “https://www.contoso.com”

$lists = @()

$webapp = Get-SPWebApplication $webappurl

$webapp.Sites | foreach-object{

$_.AllWebs | ForEach-Object{

$_.Lists | where-object {$_.Title -eq “MyUserList”} | foreach-object{

$list = New-Object System.Object

$list | Add-Member -MemberType NoteProperty -Name “Site Url” -Value $_.ParentWeb.Site.Url

$list | Add-Member -MemberType NoteProperty -Name “Web Url” -Value $_.ParentWeb.Url

$list | Add-Member -MemberType NoteProperty -Name “List Title” -Value $_.Title

$lists += $list

}

}

}

$lists | Export-Csv -NoTypeInformation -Path $outFile

The above script written for my requirement. You can create list object with all the properties that you want to capture. Once you created list object with required data you can export to csv file.

July 10, 2013 Posted by | Getting Lists, Power Shell, SharePoint 2010 | , , | Leave a comment

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)

{

continue;

}

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]

$sumWP.SummaryLinks

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