Getting the path of a program

Hello, I am new to PowerShell and need your help. I am trying to write a script, that returns the path of installed programs. For example lets say, I have Excel installed on my PC, but I don’t know its path. The script should give me the path to Excel.

Buni0409,
Welcome to the forum. :wave:t4:

May I ask …
… is it really about Excel?
… whatfor do you need this infomration? What problem do try to solve?

Hello, no it’s not about Excel. I’m working in a big company and we’re using a specific programm. There is an option to open the programm with a specific configuration via CMD command. But for the CMD command the path to the programm is needed. Since every computer will have a different path to the programm, we have to find a way to get the path of a programm, so that the comand is working on every computer

So you’re starting a command line interface from another command line interface? :thinking: :smirk:

Why is that? Most “big companies” have managed environments and would very likely use the same path for all computers?

How would you find the executable if you don’t know where it is installed? :wink:

The path differs, since some users install it into folders, which use network paths. The user of course can manually get the path of his programm and execute the command then. But we want to automate that step for the user, so that he only needs to execute that command.

hmmm … so in your “big company” users have administrative rights to do whatever they want? … wow … I really wouldn’t like to trade places with you. :smirk:

Wow - what a weird way to install programms.

First I wanted to recommend to use Get-ChildItem with the name of the executable and the default paths like “Program Files” and “Program Files (x86)” and search for it. But you’d be pretty much out of luck if a user installed a programm on a network share. If the setup for this program adds a start menu link you could try to read those links and extract the path from there.

Like I said, I am very new to PoweShell scripting and batch programming and I may be expressing my self wrong. What I mean is, that I see sometimes my User ID in document paths, so I generally persume that there can be different paths for certain data. I found this command : $files = Get-ChildItem -Path C:\ -filter *Name of Application - recurse". It does find my executable. But how do I get the path now?

You may do a big step back and start with learning the very basics of PowerShell first. This will save you from a lot of wasted time and frustrations.

How do you know? :wink:

$files = Get-ChildItem -Path C:\ -filter *Name of Application - recurse
if (@($files).count -gt 0) { Write-Host Files found! }
else { Write-Host Folder is empty! }

That’s the full command, which I used.

Hmmm … ok … again … You may do a big step back and start with learning the very basics of PowerShell first. This will save you from a lot of wasted time and frustrations.

Where did you get this code? Did you try to look into the variable you just created? I’d recommend NOT to use code you don’t understand. And I’d recommend not to use code to run for a lot of computers in a “bis company” you don’t understand.

This way you search your complete drive C: for the executable. Most applications are installed in “Program Files” or “Program Files (x86)”. I’d try to search these folders first. This could speed up your code a lot.

Regardless of that
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

Not sure if performance is an issue, but you could also get the results from the registry if the APP is installed via a windows installer package (MSI). I wrote a function a while back to find any app based on parameters to the function and chose this route.

This might get you started:

$appToFind = 'MyApp'
Get-ItemProperty -Path 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object {$_.DisplayName -Match $appToFind} | Select-Object DisplayName, InstallLocation

Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Where-Object {$_.DisplayName -Match $appToFind} | Select-Object DisplayName, InstallLocation
1 Like