4

On one of my servers (2008 R2) powershell refuses to run executables without extension, so typing cmd (or &cmd) in command prompt results in folowing error message:

The term 'cmd' is not recognized as the name of a cmdlet

Invoking executable one of the following ways pops out separate window (which executes asynchronously in respect to parent). I've tried that in x86 version of powershell and in x64 one. I've tried -Noprofile argument. PATH seems to be OK. It includes System32 and all.

The only way I've managed to execute cmd inline form powershell is opening standard cmd.exe shell, executing powershell.exe from it and executing cmd /c echo test from it. Inception, huh?

What should I try next?

Artem Tikhomirov
  • 742
  • 3
  • 9
  • 15
  • What does `&cmd` do? – jscott Jun 25 '12 at 16:20
  • It complains about unknown cmdlet. & cmd.exe pops separate window with command-line interpreter. & cmd.exe /c echo "test" executes echo in separate window and closes it after execution. & cmd.exe /c dir c:\windows\system32 pops separate window scrolling contents of system folder but parent window do not wait for it (command prompt is available for next command right away) – Artem Tikhomirov Jun 25 '12 at 16:23
  • Strange. What does `$env:PATHEXT` show? – jscott Jun 27 '12 at 01:32
  • $env:PATHEXT -eq $null returns 'True' – Artem Tikhomirov Jul 04 '12 at 14:18
  • It seems something is wrong with the `%PATHEXT%` system variable. It should have returned something like: `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC`. [*"The PATHEXT environment variable defines the list of file extensions checked by Windows NT when searching for an executable file."*](http://technet.microsoft.com/en-us/library/cc723564.aspx) Check the registry `HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT` -- if it's null, that's your problem, if not, something is altering the system variables within Powershell. Anything in your profile PS1 file? – jscott Jul 04 '12 at 16:21
  • 1
    @jscott that's exactly the problem! That registry value is absent for some reason. If you make your comment an answer, I will accept it with pleasure. – Artem Tikhomirov Jul 05 '12 at 13:47

1 Answers1

2

From our comment exchange, it appears that the System Environment Variable %PATHEXT% is not set. This is preventing the OS from determining which file extensions should be checked when searching for executables. This system variable is derived from the the following registry value:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT

If this value is missing, you may recreate it with the following:

REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /t REG_SZ /v "PATHEXT" /d ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" /f
jscott
  • 24,484
  • 8
  • 79
  • 100