Function SearchRating { param ( [Parameter(ValueFromPipeline = $true)][string[]]$Path, [Parameter(Mandatory=$true)][string[]]$Pattern, [Parameter(Mandatory=$true)][int32[]]$Rating ) $con = New-Object -ComObject ADODB.Connection $con.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';") $rs = New-Object -ComObject ADODB.Recordset ForEach($Dir in $Path) { $Pattern | ForEach-Object{ $FilePath = $Dir + "\%" $FileName = $_ -replace "\*", "%" $Query = "SELECT System.ItemPathDisplay,System.Rating FROM SYSTEMINDEX WHERE System.FileName LIKE '{0}' AND System.ItemPathDisplay LIKE '{1}'" -f $FileName, $FilePath $rs.Open($Query, $con) While(-Not $rs.EOF){ if ($Rating -contains $rs.Fields.Item("System.Rating").Value){ [PSCustomObject]@{ Path = $rs.Fields.Item("System.ItemPathDisplay").Value Rating = $rs.Fields.Item("System.Rating").Value } } $rs.MoveNext() } } } } # Example that will search (using the Windows Index) for all the MP3 files in the directory c:\Junk and its subdirectories # and return a PSCustomObject for any whose System.Rating value is found in the Rating parameter SearchRating -path c:\junk -Pattern "*.mp3" -Rating 1,2,3