Atlas Atlas - 1 year ago 300
PowerShell Question

System cannot find path/command not found error in Powershell

I have an installation of Elasticsearch that has worked fine for months but has inexplicably gone missing according to Powershell. The only thing I can think of that has changed recently is that I updated Java.

When I try to run it using the full path I get the following error:

PS C:\> C:\elasticsearch\bin\elasticsearch.bat
The system cannot find the path specified.

The path exists and there is no spelling error as you can see here:

PS C:\elasticsearch\bin> dir

Directory: C:\elasticsearch\bin

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 8/7/2016 10:13 PM 5551 elasticsearch
-a---- 8/7/2016 10:13 PM 104448 elasticsearch-service-mgr.exe
-a---- 8/7/2016 10:13 PM 103936 elasticsearch-service-x64.exe
-a---- 8/7/2016 10:13 PM 80896 elasticsearch-service-x86.exe
-a---- 8/7/2016 10:13 PM 909 elasticsearch.bat
-a---- 8/7/2016 10:13 PM 3307
-a---- 8/7/2016 10:13 PM 2814
-a---- 8/7/2016 10:13 PM 2992 plugin
-a---- 8/7/2016 10:13 PM 1303 plugin.bat
-a---- 8/7/2016 10:13 PM 6501 service.bat

When I try to run it from within the directory itself, I get the following message:

PS C:\elasticsearch\bin> elasticsearch.bat
elasticsearch.bat : The term 'elasticsearch.bat' 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
At line:1 char:1
+ elasticsearch.bat
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (elasticsearch.bat:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Suggestion [3,General]: The command elasticsearch.bat was not found, but does exist in the current location. Windows Pow
erShell does not load commands from the current location by default. If you trust this command, instead type: ".\elastic
search.bat". See "get-help about_Command_Precedence" for more details.

I don't have a strong knowledge of handling Powershell errors, so I have only tried a few things:

  1. Reinstalling Elasticsearch

  2. Adding the directory containing elasticsearch.bat to the path

  3. Running elasticsearch.bat using the command ./elasticsearch.bat

None of these change anything.

Here's the content of elasticsearch.bat:

@echo off

SETLOCAL enabledelayedexpansion
TITLE Elasticsearch 2.3.5

SET params='%*'

FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO (
SET current=%%A
SET params='%%B'
SET silent=N

IF "!current!" == "-s" (
SET silent=Y
IF "!current!" == "--silent" (
SET silent=Y

IF "!silent!" == "Y" (
SET nopauseonerror=Y
) ELSE (
IF "x!newparams!" NEQ "x" (
SET newparams=!newparams! !current!
) ELSE (
SET newparams=!current!

IF "x!params!" NEQ "x" (
GOTO loop


IF NOT DEFINED nopauseonerror (

"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" start !newparams!


Answer Source
PS C:\> C:\elasticsearch\bin\elasticsearch.bat
The system cannot find the path specified.

Are you sure that's not the output of the batch file? In other words, something in the batch file cannot find a path specified (perhaps java.exe). If PowerShell can't find the file, you'll get an error message like your second attempt.

Speaking of your second attempt:

PS C:\elasticsearch\bin> elasticsearch.bat

As the error message states, this won't work for files in the current folder. You need to explicitly specify the current folder:

PS C:\elasticsearch\bin> .\elasticsearch.bat
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download