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.

Advertisements

July 10, 2013 - Posted by | Getting Lists, Power Shell, SharePoint 2010 | , ,

No comments yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: