Powershell Open Windows Search, search for string in specific folder
I have this so far, obtained with a fair amount of help. However, I don't know where to specify a base search location. IE Let's say I want to search only in C:\temp , how would I pass that on? 

(new-object -com shell.application).FindFiles(); $wsc = (new-Object -ComObject wscript.shell); Start-Sleep -m 200; $wsc.sendkeys("Filename{enter}")
July 28th, 2015 2:37pm

Hi,

Why all of that? Use Get-ChildItem instead:

http://ss64.com/ps/get-childitem.html

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 2:39pm

What does "I want to open a GUI" mean?

What is the purpose/goal of the script? In other words, tell what you want to do, not how you think you need to do it.

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 2:47pm

What does "I want to open a GUI" mean?

What is the purpose/goal of the script? In other words, tell what you want to do, not how you think you need to

July 28th, 2015 2:55pm

The FindFiles method you are using does not have any parameters, so you can't "type" automatically into the "find" box. It is likely that you simply cannot do this the way you thought you were going to be able to do it, at least not with built-in scripting tools.
Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 3:16pm

The FindFiles method you are using does not have any parameters, so you can't "type" automatically into the "find" box. It is likely that you simply cannot do this the way you thought you were going to be able to do it, at least not with built-in script
July 28th, 2015 3:48pm

Bill, I respectfully disagree. Run the code in my original post. It will type "Filename" in the search window and run the search. I imagine if there's a way to do that in the search box, there has to be a way to tell it what folder to search in. 

The issue you'll face is that SendKeys is completely unreliable, as you have no way to force what window or input box has focus to receive your sent keystrokes. It might work while you're testing it, but I guarantee you it'll break later.

I don't have any real additional information to add here, but I just wanted to point this out so you're at least aware of the possible problems.

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 3:55pm

Bill, 

Thank you. I was not aware of that "issue" with SendKeys.

July 28th, 2015 4:39pm

I imagine if there's a way to do that in the search box, there has to be a way to tell it what folder to search in.

There doesn't have to be a way. Also, as noted, SendKeys is notoriously unreliable.

As noted: I don't think you're going to be able to get the results you want from built-in scripting tools.

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 4:58pm

Got something to work to my liking... Not directly related to the script, but since this is getting called by the VBA I'm writing, I should explain a little I guess... 

     Dim SheetNum As String
     SheetNum = ActiveCell.value
     Call Shell("explorer /root,""search-ms:query=" & SheetNum & "&crumb=location:" & RootDir & "&""")

RootDir is also a string, set as to a constant directory location. 

Adapted from a PS command someone provided me with: 

Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run ("explorer /root,""search-ms:query=exe&crumb=location:C:\Windows&""")


  • Marked as answer by EnriqueI 9 hours 56 minutes ago
  • Edited by EnriqueI 9 hours 55 minutes ago
July 28th, 2015 5:17pm

Got something to work to my liking... Not directly related to the script, but since this is getting called by the VBA I'm writing, I should explain a little I guess... 

     Dim SheetNum As String
     SheetNum = ActiveCell.value
     Call Shell("explorer /root,""search-ms:query=" & SheetNum & "&crumb=location:" & RootDir & "&""")

RootDir is also a string, set as to a constant directory location. 

Adapted from a PS command someone provided me with: 

Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run ("explorer /root,""search-ms:query=exe&crumb=location:C:\Windows&""")


  • Marked as answer by EnriqueI Tuesday, July 28, 2015 9:13 PM
  • Edited by EnriqueI Tuesday, July 28, 2015 9:14 PM
Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 9:12pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics