Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the 'where' command display any output when running in PowerShell?

Tags:

powershell

When I run where in CMD, I get output:

C:\Users\Ragesh> where calc
C:\Windows\System32\calc.exe

But the same thing in PS:

PS C:\data\code> where calc
PS C:\data\code>

Where's the output going?!

like image 673
Ragesh Avatar asked May 27 '13 14:05

Ragesh


People also ask

Is there a which command in PowerShell?

The which command is not available in PowerShell. Here is an example of the which command to view the location of gcc in Linux. PowerShell has many executable files or commands that can be executed in its shell.

How do you show commands in PowerShell?

Without parameters, Show-Command displays a command window that lists all available commands in all installed modules. To find the commands in a module, select the module from the Modules drop-down list. To select a command, click the command name.

How do I display output in a Table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.


1 Answers

The following worked for me:

PS C:\Users\Bill> where.exe calc
C:\Windows\System32\calc.exe

When you type where in PS, it is not same as executing where.exe

PS C:\Users\Bill> where  <press ENTER>

cmdlet Where-Object at command pipeline position 1
Supply values for the following parameters:
Property:

So when you type where calc it is executing Where-Object calc (the alias of Where-Object is where and ?) and thus returns nothing, and not executing where.exe calc.

You can use the Get-Command (alias gcm) cmdlet instead of where.exe. Here is an example function to make Get-Command function exactly like where.exe. If you put this in your PowerShell profile it will always be available in your session.

function which ($command) {
    Get-Command -Name $command -ErrorAction SilentlyContinue | 
        Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

The following links may be useful -

Equivalent of *Nix 'which' command in Powershell?

https://superuser.com/questions/34492/powershell-equivalent-to-unix-which-command

Hope this helps.

like image 110
Bill Avatar answered Oct 17 '22 08:10

Bill