Well, we all know SharePoint imposes limits on the list view threshold. If any list exceeds the limit, it can be a cause for performance degradation due to long running queries at the back-end [SQL].

Therefore, it’s fair to get the report, which gives us information about the lists, which are exceeding the limit of 5000 items.

The script given below provides the report.

  1. Clear-Host
  2. Write-Host -ForegroundColor Cyan "============================================================="
  3. Write-Host -ForegroundColor Magenta " SharePoint List Threshold Script "
  4. Write-Host -ForegroundColor Cyan "============================================================="
  5. Function PromptForScopeSelections
  6. {
  7. $promptTitle = "Scope selection"
  8. $promptMessage = "Please select the option to set scope for generating threshold report"
  9. $optionFarm = New-Object System.Management.Automation.Host.ChoiceDescription "&Farm", `
  10. "Generate list view threshold report for entire farm"
  11. $optionFarm.HelpMessage = "This option will generate list threshold report for entire farm"
  12. $optionWebApp = New-Object System.Management.Automation.Host.ChoiceDescription "&Web Application", `
  13. "Generate list view threshold report for single web application"
  14. $optionWebApp.HelpMessage = "This option will generate list threshold report for single web application"
  15. $optionSiteCollection = New-Object System.Management.Automation.Host.ChoiceDescription "&Site Collection", `
  16. "Generate list view threshold report for single site collection"
  17. $optionSiteCollection.HelpMessage = "This option will generate list threshold report for single site collection"
  18. $promptOptions = [System.Management.Automation.Host.ChoiceDescription[]]($optionFarm, $optionWebApp, $optionSiteCollection)
  19. $promptResult = $host.ui.PromptForChoice($promptTitle, $promptMessage, $promptOptions, 0)
  20. Return $promptResult
  21. }
  22. #Load the SharePoint snap-in in PowerShell if it is not loaded already
  23. Write-Host -ForegroundColor Yellow "Please wait while SharePoint snap-in is being loaded..."
  24. Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
  25. if((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -ne $null)
  26. {
  27. Write-Host -ForegroundColor Green "SharePoint snap-in has been loaded successfully..."
  28. #Call the function to prompt for scope selection.
  29. $UserOption = 3
  30. $UserOptionAccepted = $false
  31. While($UserOptionAccepted -ne $true)
  32. {
  33. $UserOption = PromptForScopeSelections
  34. if($UserOption -ge 0 -and $UserOption -le 3)
  35. {
  36. Write-Host -ForegroundColor Green "Input has been accepted."
  37. switch ($UserOption)
  38. {
  39. 0 {Write-Host -ForegroundColor DarkCyan "You selected farm."}
  40. 1 {Write-Host -ForegroundColor DarkCyan "You selected web application."}
  41. 2 {Write-Host -ForegroundColor DarkCyan "You selected site collection."}
  42. }
  43. $UserOptionAccepted = $true
  44. }
  45. elseif($UserOption -lt 0 -or $UserOption -ge 3 -or $UserOption -eq "" -or $UserOption -eq $null)
  46. {
  47. Write-Host -ForegroundColor Red "Invalid input..."
  48. }
  49. }
  50. if($UserOptionAccepted -eq $true)
  51. {
  52. $ScriptPath = Split-Path $MyInvocation.MyCommand.Path
  53. $ScriptDate = Get-Date -Format "dd-MMM-yyyy"
  54. $ScriptTime = Get-Date -Format "hh-mm-ss"
  55. if($UserOption -eq 0)
  56. {
  57. $ThresholdReportPath = $ScriptPath + "\" + "SharePointFarm_LVT_" + $ScriptDate + "_" + $ScriptTime + ".csv"
  58. }
  59. elseif($UserOption -eq 1)
  60. {
  61. $WebAppAccepted = $false
  62. while($WebAppAccepted -ne $true)
  63. {
  64. $WebAppURL = Read-Host -Prompt "Please Enter Web Application URL"
  65. if(($WebApplication = Get-SPWebApplication $WebAppURL -ErrorAction SilentlyContinue) -ne $null)
  66. {
  67. Write-Host -ForegroundColor Green "Web Application URL has been accepted..."
  68. $WebAppTitle = $WebApplication.Name.ToString().Replace(" ","")
  69. $WebAppAccepted = $true
  70. }
  71. else
  72. {
  73. Write-Host -ForegroundColor Red "Invalid input, please provide valid Web Application URL"
  74. }
  75. }
  76. $ThresholdReportPath = $ScriptPath + "\" + "WebApplication_" + $WebAppTitle + "_LVT_" + $ScriptDate + "_" + $ScriptTime + ".csv"
  77. }
  78. elseif($UserOption -eq 2)
  79. {
  80. $SiteAccepted = $false
  81. while($SiteAccepted -ne $true)
  82. {
  83. $SiteCollURL = Read-Host -Prompt "Please Enter Site Collection URL"
  84. if(($SiteCollection = Get-SPSite $SiteCollURL -ErrorAction SilentlyContinue) -ne $null)
  85. {
  86. Write-Host -ForegroundColor Green "Site Collection URL has been accepted..."
  87. $SiteTitle = $SiteCollection.RootWeb.Name.ToString().Replace(" ","")
  88. $SiteAccepted = $true
  89. }
  90. else
  91. {
  92. Write-Host -ForegroundColor Red "Invalid input, please provide valid Site Collection URL"
  93. }
  94. }
  95. $ThresholdReportPath = $ScriptPath + "\" + "SiteCollection_" + $SiteTitle + "_LVT_" + $ScriptDate + "_" + $ScriptTime + ".csv"
  96. }
  97. #Create Output File Headers
  98. "Site URL`tList Title`tItem Count" | Out-File $ThresholdReportPath
  99. $ListCounter = 0
  100. if($UserOption -eq 0)
  101. {
  102. $WebApps = Get-SPWebApplication
  103. ForEach($WebApp in $WebApps)
  104. {
  105. $Sites = Get-SPSite -Limit All -WebApplication $WebApp.URL
  106. ForEach($Site in $Sites)
  107. {
  108. ForEach($Web in $Site.AllWebs)
  109. {
  110. ForEach($List in $Web.Lists)
  111. {
  112. $Items = 0
  113. $Items = $List.ItemCount
  114. if($Items -ge 5000)
  115. {
  116. $ListCounter++
  117. Write-Host -BackgroundColor DarkCyan "No. of lists having more than 5K items: $ListCounter `r" -NoNewline
  118. $Web.URL + "`t" + $List.Title + "`t" + $Items | Out-File $ThresholdReportPath -Append
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. elseif($UserOption -eq 1)
  126. {
  127. $Sites = Get-SPSite -Limit All -WebApplication $WebApplication.URL
  128. ForEach($Site in $Sites)
  129. {
  130. ForEach($Web in $Site.AllWebs)
  131. {
  132. ForEach($List in $Web.Lists)
  133. {
  134. $Items = $List.ItemCount
  135. if($Items -ge 5000)
  136. {
  137. $ListCounter++
  138. Write-Host -BackgroundColor DarkCyan "No. of lists having more than 5K items: $ListCounter `r" -NoNewline
  139. $Web.URL + "`t" + $List.Title + "`t" + $Items.TOString() | Out-File $ThresholdReportPath -Append
  140. }
  141. }
  142. }
  143. }
  144. }
  145. elseif($UserOption -eq 2)
  146. {
  147. ForEach($Web in $SiteCollection.AllWebs)
  148. {
  149. ForEach($List in $Web.Lists)
  150. {
  151. $Items = $List.ItemCount
  152. if($Items -ge 5000)
  153. {
  154. $ListCounter++
  155. Write-Host -BackgroundColor DarkCyan "No. of lists having more than 5K items: $ListCounter `r" -NoNewline
  156. $Web.URL + "`t" + $List.Title + "`t" + $Items | Out-File $ThresholdReportPath -Append
  157. }
  158. }
  159. }
  160. }
  161. Write-Host " "
  162. Write-Host -ForegroundColor Cyan "Script Execution Completed..."
  163. Write-Host -ForegroundColor DarkMagenta "Output File Path is: " -NoNewline
  164. Write-Host -ForegroundColor Gray $ThresholdReportPath
  165. }
  166. else
  167. {
  168. Write-Host -ForegroundColor Red "Scope selection was not valid, terminating the exectuion..."
  169. Return
  170. }
  171. }
  172. else
  173. {
  174. Write-Host -ForegroundColor Red "SharePoint snap-in could not be loaded, terminating the execution..."
  175. }

Inputs

  1. Scope Selection: It provides you three options, as mentioned below. If you want a report for the entire Farm, press “F”. Similarly “W” or “S” for Web Application and Site Collection respectively.

    • Farm
    • Web Application
    • Site Collection

  2. If you select Web Application, then the next input you should provide is Web Application URL.
  3. If you select Site Collection, then the next input you should provide is Site Collection URL.

Once the required inputs are provided, it will go through each list in the sites and check, if it exceeds the limit of 5000 items. If yes, it will add that list to the report.

After the execution is completed, it will provide you the location, where the report is generated.

You can have a look at the report and identify the large lists. Later, remediate the lists, as per Microsoft’s recommended methods to ensure the list. The views don’t retrieve more than 5000 items at a time.

Hence, you can contribute to smooth performance for SharePoint Farm.

I hope this helps. Thanks for reading and using the script.