Last active
June 10, 2024 15:30
-
-
Save tgran2028/89df100452e35fbedc57de6fbf06f2ae to your computer and use it in GitHub Desktop.
Query Windows Search SearchIndex table by SQL query
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
<# | |
.SYNOPSIS | |
Executes a Windows Search query and returns the result as a DataTable. | |
.DESCRIPTION | |
The Query-WindowsSearch function executes a Windows Search query using the specified SQL statement and returns the result as a DataTable. | |
.PARAMETER Sql | |
The SQL statement to be executed for the Windows Search query. | |
.EXAMPLE | |
$query = "SELECT System.ItemName, System.ItemPathDisplay FROM SYSTEMINDEX WHERE System.ItemName LIKE '%example%'" | |
$result = Query-WindowsSearch -Sql $query | |
$result | Format-Table | |
.NOTES | |
This function requires the 'search.collatordso' provider to be installed on the system. It uses the 'application=windows' extended properties for the provider. | |
$cols = @( | |
'System.Comment', | |
'System.Company', | |
'System.ComputerName', | |
'System.ContentStatus', | |
'System.ContentType', | |
'System.Copyright', | |
'System.DateAccessed', | |
'System.DateAcquired', | |
'System.DateArchived', | |
'System.DateCompleted', | |
'System.DateCreated', | |
'System.DateImported', | |
'System.DateModified', | |
'System.DueDate', | |
'System.EndDate', | |
'System.FileAttributes', | |
'System.FileDescription', | |
'System.FileExtension', | |
'System.FileFRN', | |
'System.FileName', | |
'System.FileOwner', | |
'System.FlagColor', | |
'System.FlagColorText', | |
'System.FlagStatus', | |
'System.FlagStatusText', | |
'System.Identity', | |
'System.Importance', | |
'System.ImportanceText', | |
'System.IsAttachment', | |
'System.IsDeleted', | |
'System.IsEncrypted', | |
'System.IsFlagged', | |
'System.IsFlaggedComplete', | |
'System.IsIncomplete', | |
'System.IsRead', | |
'System.ItemAuthors', | |
'System.ItemDate', | |
'System.ItemFolderNameDisplay', | |
'System.ItemFolderNameDisplay', | |
'System.ItemFolderPathDisplay', | |
'System.ItemFolderPathDisplayNarrow', | |
'System.ItemName', | |
'System.ItemNameDisplay', | |
'System.ItemNamePrefix', | |
'System.ItemParticipants', | |
'System.ItemPathDisplay', | |
'System.ItemPathDisplayNarrow', | |
'System.ItemType', | |
'System.ItemTypeText', | |
'System.ItemUrl', | |
'System.Keywords', | |
'System.Kind', | |
'System.KindText', | |
'System.Language', | |
'System.MileageInformation', | |
'System.MIMEType', | |
'System.Null', | |
'System.OriginalFileName', | |
'System.ParentalRating', | |
'System.ParentalRatingReason', | |
'System.ParsingName', | |
'System.Priority', | |
'System.PriorityText', | |
'System.Project', | |
'System.ProviderItemID', | |
'System.Rating', | |
'System.RatingText', | |
'System.Sensitivity', | |
'System.SensitivityText', | |
'System.SFGAOFlags', | |
'System.Shell.OmitFromView' | |
) | |
#> | |
function Query-WindowsSearch { | |
param ( | |
[string]$Sql | |
) | |
$provider = "provider=search.collatordso;extended properties='application=windows';" | |
$connector = new-object system.data.oledb.oledbdataadapter -argument $Sql, $provider | |
$dataset = new-object system.data.dataset | |
$connector.fill($dataset) | |
$tbl = $dataset.tables[0] | |
return $tbl | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment