Query Windows Search Indexing database

Dobri Dobrev 1 Reputation point
2022-12-24T09:48:28.107+00:00

Hey guys,

I broke one of my external HDDs yesterday, it fell to the floor and now its not being detected at all..

Is there a way to query the Windows Search Indexing database to get a list of G:/paths/file names that were previously residing in drive letter "G" ?

That way at least I'd be able to get a list of things I've lost, so I can try to at least partially recreate on a new disk.

I've tried "Get-IndexedItem -Path G:/ -Recurse" however it outputs an error: resolve-path : Cannot find drive. A drive with the name 'G' does not exist. So.. I don't think it would do the job.

Windows 10 22H2 19045.2364

Hopefully someone would be able to help...

Regards,

D

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-12-24T13:33:52.037+00:00

    It's not pretty, but try this PS script. (I hacked this together years ago. Don't remember where I got the initial code.)

    # use this query to see all items.   
    #$query = "SELECT System.ItemName, system.ItemPathDisplay, System.ItemTypeText,  System.Size FROM SystemIndex"   
       
    # use this query to search on a word  
    #$query = "SELECT System.ItemName, system.ItemPathDisplay, System.ItemTypeText,  System.Size FROM SystemIndex  where contains('kawasaki')"  
      
    # https://learn.microsoft.com/en-us/windows/win32/search/-search-sql-folderdepth   
    # SCOPE='file:C:/users/'  
      
    # use this query to search on a directory  
    $query = "SELECT System.ItemName, system.ItemPathDisplay, System.ItemTypeText,  System.Size FROM SystemIndex  where SCOPE='file:G:/'"  
      
    $objConnection = New-Object -ComObject adodb.connection  
    $objrecordset = New-Object -ComObject adodb.recordset  
    $objConnection.commandtimeout = 30000  
    $objconnection.open( "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")  
    $objrecordset.open($query, $objConnection)  
    $i = 0  
    Try { $objrecordset.MoveFirst() }  
    Catch [system.exception] { "no records returned";return }  
    do   
    {  
        $i = $i + 1  
        $typ = ($objrecordset.Fields.Item("System.ITemTypeText")).value   
    	$fn = ($objrecordset.Fields.Item("System.ItemPathDisplay")).value  
        #"$i -  $typ - $fn"  
    	$fn								# just display file name  
        $size = ($objrecordset.Fields.Item("System.Size")).value   
    	$in = ($objrecordset.Fields.Item("System.ItemName")).value  
        #"       $size - $in"           # additional fields   
      
        if(-not($objrecordset.EOF))   
        {  
            $objrecordset.MoveNext()     
        }  
    } Until ($objrecordset.EOF)  
      
    "Record count $i"  
      
    $objrecordset.Close()  
    $objConnection.Close()  
    $objrecordset = $null  
    $objConnection = $null  
      
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.