PowerShell 7 "Where-Object" and its aliases return nothing
I'll try to make this as concise as possible.
I'm using PowerShell 7.2.0 and cannot get the where-object
command or its aliases where
and ?
to work.
What I want is the same functionality as with the where
command in CMD.
I've tried the command and its aliases, but none of them returns anything. I've confirmed that they're already there (no aliases need to be set) with the get-alias
command.
How can I fix this?
The equivalent in PowerShell is Get-ChildItem.
Without any parameters, it's the equivalent of dir
in cmd.
PS C:\...\DummyDesktop>gci
Directory: C:\Users\keith\DummyDesktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/30/2021 3:51 AM 11 logs.txt
-a---- 11/14/2021 11:07 PM 4833 Regex Whitespace Mode.txt
-a---- 11/9/2021 4:51 AM 1011 troubleshooting updates.txt
-a---- 11/9/2021 2:55 AM 143 Update Error Troubleshooting.url
- With no path specified, it uses the current location.
- To include subdirectories of the current location or specifed path, use the
-REcurse
(-s
) parameter. - Many simple serachs can be accomplied by using the various parameters of
Get-ChildItem
with literals and/or wildcards. - More complicated searches may require piping the results of
GetChildItem
toWhere-Object
. - As you want the fully-qualified path, you'll want the
FullName
property of the FileInfo object returned bygci
.
PS C:\...\Documents>gci ventra*
Directory: C:\Users\keith\Documents
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/2/2016 12:02 PM 27 Ventra.txt
-a---- 4/5/2021 11:13 PM 181 Ventra.zip
PS C:\...\Documents>(gci ventra*).FullName
C:\Users\keith\Documents\Ventra.txt
C:\Users\keith\Documents\Ventra.zip
THe examples you gave would look like:
(gci pyton* -Recurse).FullName
- Executed from the root or a folder known to be an ancestor of the location of
python.exe
- If searching from the root of your system drive, you'll most likely want to use the
-ErrorAction SilentlyContinue
(-ea silent
) parameter to supressAccess denied
errors.