finding file in powershell

Posted on 2013-05-21
Last Modified: 2013-05-21
I'm pretty new to powershell,

How would i use powershell to find a file and get the path. And also is it possible to use the path in a variable?

for example. I want to search for a file on my computer called  mytestfile.exe
and get the path of its location. And put that location into a variable.

I was trying to use get-childitme -recurse -include,  but i'm not sure if i am using it correctly

I seem to be able to get the  directory but how would i put the path into a variable

Question by:sirichaiphumirat
  • 3
  • 2

Accepted Solution

BT15 earned 500 total points
ID: 39185633
do you want the full filepath?

for example:

$file = get-childitem c:\ -recurse | ? {$ -eq "mytestfile.exe"}

$directory = $
$fulldirectorypath = $
$fullfilepath = $file.fullname
obviously, if you have more than one file returned, we would have to change this a bit.

Hope that helps

Author Comment

ID: 39185898
Great thanks that worked, how would you do it differently if it was more then one file.

Expert Comment

ID: 39185924
that depends on what you intend to do with your results:
This will deplay the results on the screen:

$files = get-childitem c:\ -recurse | ? {$ -eq "mytestfile.exe"}

write-host there are $files.count matching that name

foreach ($file in $files){
$directory = $
$fulldirectorypath = $
$fullfilepath = $file.fullname
write-host $
write-host the directory path is $fulldirectorypath

Author Comment

ID: 39185943
Thank you, you been very help full.

Expert Comment

ID: 39185952
you are welcome

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now