PoshCode Logo PowerShell Code Repository

Get-Command (which) by Joel Bennett 4 years ago
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/122"></script>download | new post

A function to replace Get-Command and output the commands in the correct order (the first one is the one the shell will use by default).

  1. ## This ought to be the same as Get-Command, except...
  2. ## it will output the commands in the actual order they would be used by the shell
  3. function which( [string]$command ) {
  4.    $Script:ErrorActionPreference = "SilentlyContinue"
  5.    Get-Command $command -commandType Alias
  6.    Get-Command $command -commandType Function
  7.    Get-Command $command -commandType Cmdlet
  8.    Get-Command $command -commandType Script
  9.    Get-Command $command -commandType Application
  10.    Get-Command $command -commandType ExternalScript
  11. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me