Default View Missing – Incremental Search Crawl Stuck – Solution

Problem: SharePoint incremental crawl stuck at a particular point of time – without changing the crawling status from: “Crawling Incremental”. No progress in search crawl log. No new items were included in the search crawl.

Root cause: Default view files/associations missing in some of the lists and libraries. When crawler crawls those lists and libraries, it just stuck there! I tried browsing those lists and libraries from the “View all Site content” page. Found those libraries were pointing to their settings page, instead of “AllItems.aspx”!

Solution: Create a Default View using PowerShell:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Array to Hold Result - PSObjects
$ResultsColl = @()

$WebApp = Get-SPWebApplication "https://sharepoint.crescent.com"

#Get All site collections of the Web Application 
  $SitesColl = $webApp.Sites 
   
  #Iterate through each site collection/sub-site
  foreach($Site in $SitesColl)
  {
    foreach($web in $site.AllWebs)
       {    
          foreach($list in $web.lists) #Lable for Processing all lists. Otherwise, we'll get collection modified error
            {
                if($list.hidden -eq $false)
                 {
                    if($list.defaultview -eq $null)
                    {
                     write-host $web.URL - List Name: $list.title
                     
                     $ResultItem = New-Object PSObject
                     $ResultItem | Add-Member -MemberType NoteProperty -name "WebURL" -value $web.URL 
                     $ResultItem | Add-Member -MemberType NoteProperty -Name "ListName" -value $list.title

                     #Add the object with property to an Array
                     $ResultsColl += $ResultItem
                    }
                 }
             }
             $web.dispose()
       }
        $site.dispose()
    }
  
#Process Each List and Create a View in them
#We need to process each list in this separate section 
#Because, modifying any object in the collection will thorw: Collection modified exception

foreach($Result in $ResultsColl)
{
    $web = Get-SPWeb $Result.WebURL
    $list = $web.Lists[$Result.ListName]
    
    #Create the default view
    $BaseView = $list.GetUncustomizedViewByBaseViewId(0); # Standard View
    $viewColl = $BaseView.ViewFields.ToStringCollection();
    $list.Views.Add("Default", $viewColl, $BaseView.Query, $BaseView.RowLimit, $BaseView.Paged, $true);
    
    $web.dispose();
}

#Export the result Array to CSV file
$ResultsColl | Export-CSV "D:\NoDefaultView.csv" -NoTypeInformation 
   
write-host "Script execution has been Completed!"

The above script creates a default view on a list where its missing. Run the script and initiate a crawl again.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *