This alone makes it better than where.exe, which.exe, etc which are typically limited to finding just executables. Get-Command is able to find and list all of these commands (quite akin to Bash's type -a foo). They can also be cmdlets, functions, aliases, custom executable suffixes set in $Env:PATHEXT, etc. PowerShell commands are not just executable files (. $ sal which gcm # short form of `Set-Alias which Get-Command` $ Get-Command eventvwrĪpplication eventvwr.exe c:\windows\system32\eventvwr.exeĪpplication eventvwr.msc c:\windows\system32\eventvwr.mscĪnd since powershell let's you define aliases, which can be defined like so. Under PowerShell, Get-Command will find executables anywhere in $Env:PATH. It actually returns all possibilities but you can tweak it quite easily for specific search rules. :: Function to find and print a file in the path.įor %%i in (%1) do set fullspec=%%~$PATH:i If not "x!mypathext!"="x" set mypathext=!mypathext:~1! :: Remove the extension (not overly efficient but it works). :: Then try all adorned filenames in order.įor /f "delims= " %%j in ("!mypathext!") do set myext=%%j Setlocal enableextensions enabledelayedexpansion You don't need any extra tools and it's not limited to PATH since you can substitute any environment variable (in the path format, of course) that you wish to use.Īnd, if you want one that can handle all the extensions in PATHEXT (as Windows itself does), this one does the trick: off While later versions of Windows have a where command, you can also do this with Windows XP by using the environment variable modifiers, as follows: c:\> for %i in (cmd.exe) do %~$PATH:iĬ:\> for %i in (python.exe) do %~$PATH:i
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |