34

How do you remove the PowerShell requirement that scripts and executables be preceded by ".\"?

The PowerShell warning message that is shown when "a.exe" is entered instead of ".\a.exe":

The command a.exe was not found, but does exist in the current location. Windows PowerShell doesn't load commands from the current location by default. If you trust this command, instead type ".\a.exe".
Neil Justice
  • 1,325
  • 2
  • 12
  • 25

3 Answers3

45

It is a security feature so that you do run scripts that you think you are running. That is why unlike cmd, you do not have . ( current directory) in PATH and you have to do .\my.exe etc.

If you don't want to do this and subvert this precaution, add . to your PATH:

$env:PATH =$env:PATH+";."
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 3
    Unfortunately, this trick stopped working with the latest versions (tested with PowerShell 7.1.3). The generic error message is followed by this: `Suggestion [3,General]: The command mycommand was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\mycommand". See "get-help about_Command_Precedence" for more details.` – Igor Akkerman Mar 21 '21 at 14:05
  • 1
    @IgorAkkerman, It works for me in Powershell 7.2.0. Want to try again--maybe it was a regression since fixed? – Patrick Szalapski Jan 15 '22 at 20:43
  • @PatrickSzalapski Thanks for the clue, it works for me in 7.2.1 as well. – Igor Akkerman Jan 16 '22 at 22:41
  • This no longer works for me in 7.2.4. Anyone have any other ideas? – Patrick Szalapski May 31 '22 at 18:41
  • Is there a way to subvert the precaution permanently? – Egret Aug 01 '22 at 01:51
2

add in your path (evironment variable) the path where you usually put your script and exe file.

CB.
  • 58,865
  • 9
  • 159
  • 159
-1

Rename your script file so that it starts with a '.'.

See https://github.com/PowerShell/PowerShell/issues/9468

msftrncs
  • 69
  • 3