Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

finding multiple instances of filename

$
0
0

Goal: I need to run a command line to uninstall a program on some of our work computers. The command line includes the path to an executable and then some parameters.

Possible scenarios: The executable in question could exist in one or more locations, as the program typically does a horrible job cleaning up after itself when upgrading from one version to the next.

So on some computers, this executable could exist once; on other computers it could exist multiple times. I know that the executable will exist somewhere beneath the C:\ProgramData folder.

I also know that the directory path will not necessarily be the same on two computers for the same version of the executable: so on computer A, the path to the executable could be C:\ProgramData\1234\file.exe; while on computer B, the path could be C:\ProgramData\5678\file.exe

I know how to search for multiple instances of the file:

Get-ChildItem -Path C:\myFolder -Filter foo.exe -Recurse-ErrorAction SilentlyContinue -Force

What I'm not sure how to do in PowerShell language is say "Take the directory path of each instance found and then use that to build the command line that I want to run."

The work computers in question are running Microsoft Windows 7, 64-bit and have PowerShell version 4 installed.

Thank you.


Viewing all articles
Browse latest Browse all 6937

Trending Articles