2

I would like powershell to use the environment variable "PATH" to resolve executables. I'm sure it should be able to do this, but here is what I get.

PS C:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

PS C:\> ${ENV:PATH} = "C:\WINDOWS\System32\"
PS C:\> ls ${ENV:PATH}\cmd.exe


Directory: C:\WINDOWS\System32


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        22/08/2013   8:03 PM     355840 cmd.exe

PS C:\> & cmd.exe
& : The term 'cmd.exe' 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.
At line:1 char:3
+ & cmd.exe
+   ~~~~~~~
+ CategoryInfo          : ObjectNotFound: (cmd.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
simonhaines
  • 481
  • 7
  • 22
  • see this question: http://stackoverflow.com/questions/714877/setting-windows-powershell-path-variable – Matt Aug 18 '14 at 00:42
  • you can use `$env:Path` – Matt Aug 18 '14 at 00:43
  • It should use the Path variable by default and System32 should be on it by default. Are you running the 32-bit or 64-bit version? I'm just wondering if maybe you are getting some weird file system redirection issue accessing C:\Windows\System32. – Mike Zboray Aug 18 '14 at 00:47
  • 2
    What happens if you run `Get-Command -Type Application`? – briantist Aug 18 '14 at 01:05
  • 1
    Ah thanks, I'd overwritten my PATHEXT variable and forgot to include ".exe". If this were an answer, I'd accept it. – simonhaines Aug 18 '14 at 01:16

1 Answers1

5

Run Get-Command -Type Application to see what PowerShell is seeing as valid executables.

You may find a clue as to what's going on, such as all of the listed applications have (or don't have) a certain extension, which could indicate a problem with the PATHEXT environment variable.

briantist
  • 45,546
  • 6
  • 82
  • 127