Avoid dot backslash Windows 10 Powershell
This is a very annoying thing, to run any .exe
that is inside the current directory in Powershell, I am required to use a .\
ahead.
For example, if I have the program fastboot.exe
inside the current folder I can not simply type fastboot
, as it does inside cmd
. I'm forced to type:
.\fastboot
If I just type fastboot
(without .\
I get some error like:
The term 'fastboot' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ fastboot + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (fastboot:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
How to avoid this?
Solution 1:
If you don't like typing .\command.ps1
, You can just type command
and hit tab. If there is a command.ps1 file in the current directory it will be auto-completed.
I think this is ergonomic enough to keep the security benefit of the default behavior.
Solution 2:
Powershell does not load commands from the current location by default.
Suggestion [3,General]: The command xxx.exe was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type ".\xxx.exe". See "get-help about_Command_Precedence" for more details.
So you are left with two options
-
Lower the security barrier by adding the current directory to you path
$env:path ="$($env:path);."
Get into the habbit of always prefixing the command with
.\