Get full contents of file by querying Windows Search Index

613 views Asked by At

I have written this shell script to query the windows search index.

$sql = "SELECT  System.ItemName, System.ItemPathDisplay, SYSTEM.FileOwner, System.ItemType
FROM SYSTEMINDEX
WHERE (SCOPE = 'C:\Users\Raghib\Desktop\1001') AND (CONTAINS(System.Search.Contents,'*Langevin*') OR CONTAINS(System.FileName,'*Langevin*')
OR CONTAINS(System.FILEOWNER,'*Langevin*'))"

$provider = "provider=search.collatordso;extended properties='application=windows';"
$connector = new-object system.data.oledb.oledbdataadapter -argument $sql, $provider
$dataset = new-object system.data.dataset

if ($connector.fill($dataset)) 
{
    $dataset.tables[0] | select-object System.ItemName, System.ItemPathDisplay, 
    SYSTEM.FileOwner, System.ItemType | format-table -autosize * 
}

It returns all the metadata of the file but I want to get all the contents of the file also. Is there any way to do so?

Here is the link to SYSTEMINDEX column properties: https://learn.microsoft.com/en-us/previous-versions//ff521735(v=vs.85)?redirectedfrom=MSDN

1

There are 1 answers

0
xldude On

According to Microsoft documentation System.Search.Contents property cannot be retrived.

"This property is for query restrictions only; it cannot be retrieved in a query result. "

see: https://learn.microsoft.com/en-us/windows/win32/properties/props-system-search-contents