Beniamino_Baggins Beniamino_Baggins - 4 years ago 214
PowerShell Question

Locate file in folder further down the hierarchy

I need to locate a .exe file and run it, only knowing the directory which is a few levels higher than the .exe file

EG If I have this folder structure:


and I only know the test folder, I need to get the path to program.exe, without knowing the name of the .exe file either (but there is only one .exe file).

So something like:

gcm *.exe test

Where test is the source folder to look in.

How do I do this?

Answer Source

This sounds like what you're looking for:

$path = 'test'
$program = Get-ChildItem -Path $path -Filter *.exe -Recurse
& $program.FullName

The & operator there is the call operator; it can run an executable given the full path to it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download