PowerShell equivalent of BASH (etc) 'type' command? PowerShell equivalent of BASH (etc) 'type' command? windows windows

PowerShell equivalent of BASH (etc) 'type' command?


An equivalent is Get-Command.

PS C:\> Get-Command lsCommandType     Name       Definition-----------     ----       ----------Alias           ls         Get-ChildItemApplication     ls.exe     D:\usr\local\wbin\ls.exeApplication     ls.exe     C:\Program Files (x86)\Git\bin\ls.exe

Windows 10 Update:

Since I've posted this answer, it appears that the behavior of Get-Command has changed. To include all results (in the style of Un*x) type), now I need to pass the -All flag, like so:

PS C:\> Get-Command -All lsCommandType     Name                 Version    Source-----------     ----                 -------    ------Alias           ls -> Get-ChildItemApplication     ls.exe               0.0.0.0    C:\Program Files (x86)\Git\usr\bin\ls.exe

As noted in a comment, this doesn't include the Definition column as was the previous behavior. I can't determine a command-line argument to add the definition column, but as noted by @voutasaurus in the comment below, one can use:

PS C:\> (Get-Command -All ls).DefinitionGet-ChildItemC:\Program Files (x86)\Git\usr\bin\ls.exe

Version information for reference (I odn't have the version information associated with the original answer text, but I'm guessing that it was Windows 7):

PS C:\> [System.Environment]::OSVersion.VersionMajor  Minor  Build  Revision-----  -----  -----  --------10     0      15063  0


Get-Command has a -ShowCommandInfo parameter that does this. It also works for functions defined in $profile :

PS C:\Users\vp937ll> Get-Command l -ShowCommandInfoName          : lModuleName    :Module        : @{Name=}CommandType   : FunctionDefinition    : Get-ChildItem | Sort-Object -Property LastWriteTime -DescendingParameterSets : {@{Name=__AllParameterSets; IsDefault=False; Parameters=System.Management.Automation.PSObject[]}}


Since you tagged this with Shell, in addition to PowerShell's Get-Command, there's where.exe:

PS C:\> where.exe notepadC:\Windows\System32\notepad.exeC:\Windows\notepad.exe

The command just looks for a file with the specified name through the path:

PS C:\> where.exe readme.*C:\Python31\README.txtC:\Program Files (x86)\wget\READMEC:\Program Files (x86)\SysinternalsSuite\readme.txt

Note that when calling this command from PowerShell, you must call it as where.exe because Where-Object is aliased to where.