POWERSHELL searching for path to files using WHERE command [closed]
up vote
-1
down vote
favorite
I have problem with using where command. I have to search for specific exe file inside C:Program Files and output path of it.
powershell where
closed as too broad by Richard, Adam Luniewski, arco444, gvee, Ansgar Wiechers Nov 7 at 10:03
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-1
down vote
favorite
I have problem with using where command. I have to search for specific exe file inside C:Program Files and output path of it.
powershell where
closed as too broad by Richard, Adam Luniewski, arco444, gvee, Ansgar Wiechers Nov 7 at 10:03
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality).Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using$_.FullName
to get the full path to the file /Get-Content
to read the file's contents.
– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
ps. TypingGet-Help Get-ChildItem
/Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.
– JohnLBevan
Nov 7 at 9:23
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have problem with using where command. I have to search for specific exe file inside C:Program Files and output path of it.
powershell where
I have problem with using where command. I have to search for specific exe file inside C:Program Files and output path of it.
powershell where
powershell where
edited Nov 7 at 10:23
asked Nov 7 at 9:17
Dixon
32
32
closed as too broad by Richard, Adam Luniewski, arco444, gvee, Ansgar Wiechers Nov 7 at 10:03
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Richard, Adam Luniewski, arco444, gvee, Ansgar Wiechers Nov 7 at 10:03
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality).Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using$_.FullName
to get the full path to the file /Get-Content
to read the file's contents.
– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
ps. TypingGet-Help Get-ChildItem
/Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.
– JohnLBevan
Nov 7 at 9:23
add a comment |
1
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality).Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using$_.FullName
to get the full path to the file /Get-Content
to read the file's contents.
– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
ps. TypingGet-Help Get-ChildItem
/Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.
– JohnLBevan
Nov 7 at 9:23
1
1
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality). Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using $_.FullName
to get the full path to the file / Get-Content
to read the file's contents.– JohnLBevan
Nov 7 at 9:21
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality). Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using $_.FullName
to get the full path to the file / Get-Content
to read the file's contents.– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
ps. Typing
Get-Help Get-ChildItem
/ Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.– JohnLBevan
Nov 7 at 9:23
ps. Typing
Get-Help Get-ChildItem
/ Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.– JohnLBevan
Nov 7 at 9:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Here's a script that does something along the lines you're after:
Get-ChildItem -Path $env:ProgramFiles -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue | Where-Object {$_.FullName -like '*git*'} | Select-Object FullName
Get-ChildItem
lists all files & folders under the given path
-Path $env:ProgramFiles
sends the value from the environment variable "ProgramFiles" (i.e. the path to the program files directory) to the Path argument ofGet-ChildItem
-Recurse
says to include subfolders (all the way down).
-Filter '*.exe'
says to only return files with the .exe extension.
-ErrorAction SilentlyContinue
says "if some issue occurs (e.g. you don't have access to a folder) don't throw up error messages; just carry on".
|
is a pipeline character / says to send each output from the current command to the pipeline input of the next command. I.e. in this caseGet-ChildItem
is returning a bunch ofFileSystemInfo
objects, which get passed one by one toWhere-Object
for filtering.
Where-Object
evaluates a boolean expression; anything that evaluates totrue
goes on through the pipeline; anything resulting infalse
gets blocked/ignored by all further operations.
{$_.FullName -like '*git*'}
is the condition to evaluate.$_
is the current pipeline variable; i.e. each of the FileSystemInfo objects passed from theGet-ChildItem
command's output. TheFullName
is the full path to the file/folder being represented (e.g."c:program filessomethingsomethingelsefile.exe"
.-like '*git*'
says "return any values where the full path contains the textgit
within the path (i.e.*
being wildcard characters.
| Select-Object FullName
then takes the results that are passed on by theWhere-Object
(i.e. those which matched the condition), and returns the single property,FullName
from those objects; so you get a list of the exes' paths, rather than all of the properties describing them from the FileSystemInfo objects.
Full PowerShell documentation can be found here: https://docs.microsoft.com/en-us/powershell/
For help on any specific command, type Get-Help command
, e.g. Get-Help Get-ChildItem
.
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Here's a script that does something along the lines you're after:
Get-ChildItem -Path $env:ProgramFiles -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue | Where-Object {$_.FullName -like '*git*'} | Select-Object FullName
Get-ChildItem
lists all files & folders under the given path
-Path $env:ProgramFiles
sends the value from the environment variable "ProgramFiles" (i.e. the path to the program files directory) to the Path argument ofGet-ChildItem
-Recurse
says to include subfolders (all the way down).
-Filter '*.exe'
says to only return files with the .exe extension.
-ErrorAction SilentlyContinue
says "if some issue occurs (e.g. you don't have access to a folder) don't throw up error messages; just carry on".
|
is a pipeline character / says to send each output from the current command to the pipeline input of the next command. I.e. in this caseGet-ChildItem
is returning a bunch ofFileSystemInfo
objects, which get passed one by one toWhere-Object
for filtering.
Where-Object
evaluates a boolean expression; anything that evaluates totrue
goes on through the pipeline; anything resulting infalse
gets blocked/ignored by all further operations.
{$_.FullName -like '*git*'}
is the condition to evaluate.$_
is the current pipeline variable; i.e. each of the FileSystemInfo objects passed from theGet-ChildItem
command's output. TheFullName
is the full path to the file/folder being represented (e.g."c:program filessomethingsomethingelsefile.exe"
.-like '*git*'
says "return any values where the full path contains the textgit
within the path (i.e.*
being wildcard characters.
| Select-Object FullName
then takes the results that are passed on by theWhere-Object
(i.e. those which matched the condition), and returns the single property,FullName
from those objects; so you get a list of the exes' paths, rather than all of the properties describing them from the FileSystemInfo objects.
Full PowerShell documentation can be found here: https://docs.microsoft.com/en-us/powershell/
For help on any specific command, type Get-Help command
, e.g. Get-Help Get-ChildItem
.
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
add a comment |
up vote
1
down vote
accepted
Here's a script that does something along the lines you're after:
Get-ChildItem -Path $env:ProgramFiles -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue | Where-Object {$_.FullName -like '*git*'} | Select-Object FullName
Get-ChildItem
lists all files & folders under the given path
-Path $env:ProgramFiles
sends the value from the environment variable "ProgramFiles" (i.e. the path to the program files directory) to the Path argument ofGet-ChildItem
-Recurse
says to include subfolders (all the way down).
-Filter '*.exe'
says to only return files with the .exe extension.
-ErrorAction SilentlyContinue
says "if some issue occurs (e.g. you don't have access to a folder) don't throw up error messages; just carry on".
|
is a pipeline character / says to send each output from the current command to the pipeline input of the next command. I.e. in this caseGet-ChildItem
is returning a bunch ofFileSystemInfo
objects, which get passed one by one toWhere-Object
for filtering.
Where-Object
evaluates a boolean expression; anything that evaluates totrue
goes on through the pipeline; anything resulting infalse
gets blocked/ignored by all further operations.
{$_.FullName -like '*git*'}
is the condition to evaluate.$_
is the current pipeline variable; i.e. each of the FileSystemInfo objects passed from theGet-ChildItem
command's output. TheFullName
is the full path to the file/folder being represented (e.g."c:program filessomethingsomethingelsefile.exe"
.-like '*git*'
says "return any values where the full path contains the textgit
within the path (i.e.*
being wildcard characters.
| Select-Object FullName
then takes the results that are passed on by theWhere-Object
(i.e. those which matched the condition), and returns the single property,FullName
from those objects; so you get a list of the exes' paths, rather than all of the properties describing them from the FileSystemInfo objects.
Full PowerShell documentation can be found here: https://docs.microsoft.com/en-us/powershell/
For help on any specific command, type Get-Help command
, e.g. Get-Help Get-ChildItem
.
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Here's a script that does something along the lines you're after:
Get-ChildItem -Path $env:ProgramFiles -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue | Where-Object {$_.FullName -like '*git*'} | Select-Object FullName
Get-ChildItem
lists all files & folders under the given path
-Path $env:ProgramFiles
sends the value from the environment variable "ProgramFiles" (i.e. the path to the program files directory) to the Path argument ofGet-ChildItem
-Recurse
says to include subfolders (all the way down).
-Filter '*.exe'
says to only return files with the .exe extension.
-ErrorAction SilentlyContinue
says "if some issue occurs (e.g. you don't have access to a folder) don't throw up error messages; just carry on".
|
is a pipeline character / says to send each output from the current command to the pipeline input of the next command. I.e. in this caseGet-ChildItem
is returning a bunch ofFileSystemInfo
objects, which get passed one by one toWhere-Object
for filtering.
Where-Object
evaluates a boolean expression; anything that evaluates totrue
goes on through the pipeline; anything resulting infalse
gets blocked/ignored by all further operations.
{$_.FullName -like '*git*'}
is the condition to evaluate.$_
is the current pipeline variable; i.e. each of the FileSystemInfo objects passed from theGet-ChildItem
command's output. TheFullName
is the full path to the file/folder being represented (e.g."c:program filessomethingsomethingelsefile.exe"
.-like '*git*'
says "return any values where the full path contains the textgit
within the path (i.e.*
being wildcard characters.
| Select-Object FullName
then takes the results that are passed on by theWhere-Object
(i.e. those which matched the condition), and returns the single property,FullName
from those objects; so you get a list of the exes' paths, rather than all of the properties describing them from the FileSystemInfo objects.
Full PowerShell documentation can be found here: https://docs.microsoft.com/en-us/powershell/
For help on any specific command, type Get-Help command
, e.g. Get-Help Get-ChildItem
.
Here's a script that does something along the lines you're after:
Get-ChildItem -Path $env:ProgramFiles -Recurse -Filter '*.exe' -ErrorAction SilentlyContinue | Where-Object {$_.FullName -like '*git*'} | Select-Object FullName
Get-ChildItem
lists all files & folders under the given path
-Path $env:ProgramFiles
sends the value from the environment variable "ProgramFiles" (i.e. the path to the program files directory) to the Path argument ofGet-ChildItem
-Recurse
says to include subfolders (all the way down).
-Filter '*.exe'
says to only return files with the .exe extension.
-ErrorAction SilentlyContinue
says "if some issue occurs (e.g. you don't have access to a folder) don't throw up error messages; just carry on".
|
is a pipeline character / says to send each output from the current command to the pipeline input of the next command. I.e. in this caseGet-ChildItem
is returning a bunch ofFileSystemInfo
objects, which get passed one by one toWhere-Object
for filtering.
Where-Object
evaluates a boolean expression; anything that evaluates totrue
goes on through the pipeline; anything resulting infalse
gets blocked/ignored by all further operations.
{$_.FullName -like '*git*'}
is the condition to evaluate.$_
is the current pipeline variable; i.e. each of the FileSystemInfo objects passed from theGet-ChildItem
command's output. TheFullName
is the full path to the file/folder being represented (e.g."c:program filessomethingsomethingelsefile.exe"
.-like '*git*'
says "return any values where the full path contains the textgit
within the path (i.e.*
being wildcard characters.
| Select-Object FullName
then takes the results that are passed on by theWhere-Object
(i.e. those which matched the condition), and returns the single property,FullName
from those objects; so you get a list of the exes' paths, rather than all of the properties describing them from the FileSystemInfo objects.
Full PowerShell documentation can be found here: https://docs.microsoft.com/en-us/powershell/
For help on any specific command, type Get-Help command
, e.g. Get-Help Get-ChildItem
.
answered Nov 7 at 9:37
JohnLBevan
14k145102
14k145102
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
add a comment |
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
1
1
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
I really appreciate your help. Especially detailed description of commands. I've been trying to figure this out for hours using docs.microsoft.com/en-us/powershell , your post clarifies everything.
– Dixon
Nov 7 at 10:34
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
No worries / good luck. FYI: I originally taught myself PS using this book: amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/…
– JohnLBevan
Nov 7 at 10:39
add a comment |
1
Get-ChildItem
will allow you to find files under a folder (this has some very basic filter functionality).Where-Object
will allow you to then apply a filter to the results (as complex as you like; e.g. using$_.FullName
to get the full path to the file /Get-Content
to read the file's contents.– JohnLBevan
Nov 7 at 9:21
Please can you provide more info on what you're trying to do and what you've tried already so we can help you further.
– JohnLBevan
Nov 7 at 9:21
ps. Typing
Get-Help Get-ChildItem
/Get-Help Where-Object
(you see the pattern) will allow you to learn more about these commands within PowerShell itself.– JohnLBevan
Nov 7 at 9:23