SharePoint and Large Lists


# a colleague recently posted an incredibly useful bit of code
# which can show us those potentially problematic Large Lists.
# enjoy!

param( $PathToSitesFolder = "." )

function fnLargeListsFromSubWebs {
param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] $ParentWeb )
    process {
 $largeLists = $ParentWeb.SPListCollection.SPList | ? { [int] ($_.ItemCount) -ge 2000 }
 if ($largeLists) {
  $largeLists | % { $_ | Add-Member -MemberType NoteProperty -Name Url -Value $ParentWeb.Url }
  Write-Output $largeLists
 }
 if ($ParentWeb.SPWebCollection.SPWeb) {
  $ParentWeb.SPWebCollection.SPWeb | fnLargeListsFromSubWebs
 }
    }
}

$xmls = @()
Get-ChildItem $PathToSitesFolder\*.site | % { $xmls += [xml] (Get-Content $_.FullName) }

$lists = foreach ( $xml in $xmls ) {
 $xml.SPSite.SPWebCollection.SPWeb | fnLargeListsFromSubwebs
}

$lists | Sort-Object Url | Select-Object Title, ItemCount, Url, ParentWebUrl, DefaultViewUrl | Export-Csv $PathToSitesFolder\LargeLists.csv -NoTypeInformation


Comments (0)

Skip to main content