Required Files: None
Monitor the Windows Search Database, try to remediate and also alert if it has grown out of control
Import-Module $env:SyncroModule $MaxSizeInGB = '50' $getservice = Get-service "wsearch" -ErrorAction SilentlyContinue if($getservice.Status -eq "running"){ $CurrentLoc = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Search\" -name DataDirectory $File = Get-item -path "$($CurrentLoc.DataDirectory)\Applications\Windows\windows.edb" $FileSize = [math]::truncate($file.length / 1GB) if($FileSize -gt $MaxSizeInGB){ $searchHealth = "SearchDB is $($filesize)GB - Please investigate" } if (!$SearchHealth) { $SearchHealth = "Healthy" } } write-host "SEARCH HEALTH: $SearchHealth " if($SearchHealth -ne "Healthy"){ Rmm-Alert -Category "search_db_health" -Body "Windows Search Database Health triggered $SearchHealth on $(%computername%). We are attempting to rebuild the Search DB automatically." #### BEGIN REBUILD THE SEARCH DB - SCHEDULE THIS SCRIPT DURING MAINTENANCE WINDOWS ONLY ##### Stop-Service Wsearch $CurrentLoc = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Search\" -name DataDirectory remove-item $CurrentLoc.DataDirectory -force -Recurse Start-Service Wsearch #### END REBUILDING THE SEARCH DB ##### } |