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
5
  • see this question: stackoverflow.com/questions/714877/… Commented Aug 18, 2014 at 0:42
  • you can use $env:Path Commented Aug 18, 2014 at 0: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. Commented Aug 18, 2014 at 0:47
  • 2
    What happens if you run Get-Command -Type Application? Commented Aug 18, 2014 at 1:05
  • 1
    Ah thanks, I'd overwritten my PATHEXT variable and forgot to include ".exe". If this were an answer, I'd accept it. Commented Aug 18, 2014 at 1:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.