41

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".

3 Answers 3

47

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+";."
Sign up to request clarification or add additional context in comments.

6 Comments

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.
@IgorAkkerman, It works for me in Powershell 7.2.0. Want to try again--maybe it was a regression since fixed?
@PatrickSzalapski Thanks for the clue, it works for me in 7.2.1 as well.
This no longer works for me in 7.2.4. Anyone have any other ideas?
Is there a way to subvert the precaution permanently?
|
3

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

1 Comment

This is my environment variable: ANDROID_HOME: C:\Users\berke\AppData\Local\Android\Sdk\platform-tools In platform-tools there is adb.exe i cant run adb exe globally what should i do...?
-2

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.