Created
November 28, 2019 01:43
-
-
Save jkniiv/bb568f1d7adc11d1ee8fc6b7add0e1bb to your computer and use it in GitHub Desktop.
Returns a GridView of all the "scope rules" for the standard search index of Windows Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns a visual list via PowerShell's Out-GridView of all the "scope rules" for the standard search index | |
# in Windows Search. These are objects that represent files and folders to be included in or excluded from | |
# the search index while Windows Search is indexing (also called "crawling") your files. | |
# This code is basically from here (except for some re-formatting and new comments by me [Jarkko Kniivilä aka | |
# 'jkniiv']): | |
# https://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/ | |
# See also the following script (not mine) for inspiration if you're interested: | |
# https://github.com/IntelliTect/PSToolbox/blob/master/Functions/WindowsSearchIndex.ps1 | |
# Load the dll (easiest to be found here https://github.com/IntelliTect/PSToolbox/tree/master/Lib) | |
Add-Type -Path .\Microsoft.Search.Interop.dll | |
# Create an instance of CSearchManagerClass | |
$searchManager = New-Object Microsoft.Search.Interop.CSearchManagerClass | |
# We are interested in the standard search index (a search index is also known as a catalog in indexing | |
# and searching jargon) | |
$catalog = $searchManager.GetCatalog("SystemIndex") | |
# We need the scope rule manager for the crawler, i.e. the indexer part of Windows Search | |
$crawlScopeManager = $catalog.GetCrawlScopeManager() | |
# Next we set some variables to use in enumerating the results | |
$scopeRules = @() # The array that will hold our scope rules | |
[Microsoft.Search.Interop.CSearchScopeRule]$scopeRule = $null # A single scope rule. This will be passed | |
# as a reference to the enumeration process. | |
# It will receive the scope rule as we | |
# enumerate. | |
$begin = $true # A variable to test for the first run of the enumeration | |
# Let's grab the enumeration object from the scope rule manager and start enumerating | |
$scopeRulesEnum = $crawlScopeManager.EnumerateScopeRules() | |
while ($scopeRule -ne $null -or $begin) { # We either have a scope rule or we're just beginning | |
$scopeRulesEnum.Next(1, [ref]$scopeRule, [ref]$null) | |
$scopeRules += $scopeRule | |
$begin = $false | |
} | |
# Finally, let's show what we got :) | |
$scopeRules | Out-GridView -Wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment