Skip to content

Instantly share code, notes, and snippets.

@codingoutloud codingoutloud/which.ps1
Last active Dec 24, 2015

Embed
What would you like to do?
Implements the Unix shell 'which' command using PowerShell
<#
Implements the Unix shell 'which' command using PowerShell.
original: https://gist.github.com/codingoutloud/6782961
#>
function WhichOnes
{
if ($args.Count -eq 0)
{
# obviously use of 'which' in usage text is a hack (since it is chosen to match the alias)
Write-Host "usage: which [cmd1] [cmd2] ..."
}
else
{
Get-Command $args -All -ErrorAction SilentlyContinue | Format-Table Definition
}
}
New-Alias which WhichOnes
@codingoutloud

This comment has been minimized.

Copy link
Owner Author

commented Oct 1, 2013

PowerShell 'which'

original is here

Implements the Unix shell 'which' command using PowerShell.

Usage

_which grep_ -- lists paths to any existing grep commands available.

To add to your PowerShell environment

  • Open a PowerShell command prompt
  • Edit your profile startup script using _notepad $profile_ (see Troubleshooting below if you get an error)
  • Paste in the contents of this gist
  • Save the file
  • Close PowerShell and start a new PowerShell shell session
  • ... and it should work.

Troubleshooting

  • You need to open a new PowerShell shell in order for the script to be run automatically. So this will be a problem only the first time after you've created the script.
  • If notepad complains that the path does not exist during the "notepad $profile" step, run the following command first: _mkdir $env:USERPROFILE\WindowsPowerShell_
  • If PowerShell complains about the script with a message similar to Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system. then your PowerShell environment does not have sufficient permissions to execute unsigned scripts locally. You can fix this by running a PowerShell shell as adminstrator and then executing the command Set-ExecutionPolicy RemoteSigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.