Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Forked from ferventcoder/Where.ps1
Created April 5, 2012 03:23
Show Gist options
  • Save staxmanade/2307715 to your computer and use it in GitHub Desktop.
Save staxmanade/2307715 to your computer and use it in GitHub Desktop.
Somebody's where.exe implementation as powershell ;)
function where-is($command) {
(ls env:\path).Value.split(';') | `
where { $_ } | `
%{ [System.Environment]::ExpandEnvironmentVariables($_) } | `
where { test-path $_ } |`
%{ ls "$_\*" -include *.bat,*.exe,*cmd } | `
%{ $file = $_.Name; `
if($file -and ($file -eq $command -or `
$file -eq ($command + '.exe') -or `
$file -eq ($command + '.bat') -or `
$file -eq ($command + '.cmd'))) `
{ `
$_.FullName `
} `
} | `
select -unique
}
@ferventcoder
Copy link

Much prettier.. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment