Beniamino_Baggins Beniamino_Baggins - 1 month ago 5x
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?


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.