Link to home
Create AccountLog in
Avatar of sirichaiphumirat
sirichaiphumiratFlag for United States of America

asked on

finding file in powershell

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

Avatar of BT15
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of sirichaiphumirat


Great thanks that worked, how would you do it differently if it was more then one file.
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
Thank you, you been very help full.
you are welcome