145

Where is the Powershell (version 2.0) located? What is the path to Powershell.exe? I have Windows Server 2008 and Powershell installed. When I look at this folder:

PS C:\Windows\System32\WindowsPowerShell> dir


    Directory: C:\Windows\System32\WindowsPowerShell


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         20.4.2010     17:09            v1.0

I have only Powershell v1.0. But when I type

PS C:\> $Host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1


PS C:\>

It shows that I have v2.0 installed.

jjoras
  • 2,001
  • 5
  • 18
  • 16

6 Answers6

205

I believe it's in C:\Windows\System32\WindowsPowershell\v1.0\. In order to confuse the innocent, MS kept it in a directory labeled "v1.0". Running this on Windows 7 and checking the version number via $Host.Version (Determine installed PowerShell version) shows it's 2.0.

Another option is type $PSVersionTable at the command prompt. If you are running v2.0, the output will be:

Name                           Value
----                           -----
CLRVersion                     2.0.50727.4927
BuildVersion                   6.1.7600.16385
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

If you're running version 1.0, the variable doesn't exist and there will be no output.

Localization PowerShell version 1.0, 2.0, 3.0, 4.0:

  • 64 bits version: C:\Windows\System32\WindowsPowerShell\v1.0\
  • 32 bits version: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\
ntrch
  • 76
  • 1
  • 22
doobop
  • 4,465
  • 2
  • 28
  • 39
63

I think $PsHome has the information you're after?

PS .> $PsHome
C:\Windows\System32\WindowsPowerShell\v1.0

PS .> Get-Help about_automatic_variables

TOPIC
    about_Automatic_Variables ...

Simon B
  • 731
  • 5
  • 3
42

Here is one way...

(Get-Process powershell | select -First 1).Path

Here is possibly a better way, as it returns the first hit on the path, just like if you had ran Powershell from a command prompt...

(Get-Command powershell.exe).Definition
Nathan Hartley
  • 4,005
  • 2
  • 43
  • 46
  • 4
    As far as I'm concerned, this is a better answer than the one currently voted up to 35. The original question seemed to be about the path to the executable, with version information being incidental to the question. This answer directly addresses that question, bypassing even the "supposed to be" answer and letting a person find out exactly where the exe is on their own system, even if that system differs from default. (This is what I came here looking for, so I appreciate it.) – Todd Walton Feb 05 '14 at 19:06
  • 1
    Searching based on the executable being `powershell.exe` is a little too relaxed, since you could easily rename another executable to `powershell.exe`, and have it pick up that process instead. `Get-Process -Id $PID` would work, though I'm not sure what version `$PID` was introduced in. – Charles Grunwald May 19 '16 at 20:35
  • 1
    I see your "too relaxed" point, however, using the $PID will return the current host, which may not be a Powershell interpreter. Like Powershell_ise.exe, for instance. – Nathan Hartley May 31 '16 at 19:00
  • maybe since November 2011 properties have changed. For me (in July 2016, using Windows Server 2012) the property .Source does not exist, Instead, I can use the property .Definition which returns: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe". My $PSHome variable contains: "C:\Windows\System32\WindowsPowerShell\v1.0" Also, if you use get-process, consider using 'powershell*' instead of just powershell, in case you are using powershell_ise. HTH – Marcelo Finki Jul 04 '16 at 14:32
  • Changed answer from using .Source to .Definition. – Nathan Hartley Aug 04 '16 at 14:07
  • @NathanHartley why is it called `definition` and not `source` (the displayed column name) ? –  Nov 11 '17 at 19:19
  • Interesting. There have been some changes over the years. It seems, that property started as Source, changed to Definition and is now (tested in v5.1) available via both Source and Destination. – Nathan Hartley Nov 11 '17 at 23:23
  • With Get-Process you have to be careful that you get the correct architecture. It's possible to get the path to 64-bit PowerShell when you are running from 32-bit PowerShell, depending on what processes are running. (There's also the possibility of renaming random executables as "powershell" as @CharlesGrunwald points out.) – Jack Taylor Mar 25 '21 at 02:49
  • With Get-Command you always get the path to 64-bit PowerShell, although I think Microsoft auto-converts the folder name to the correct architecture (not sure of the details there). – Jack Taylor Mar 25 '21 at 02:49
13

It is always C:\Windows\System32\WindowsPowershell\v1.0. It was left like that for backward compability is what I heard or read somewhere.

ravikanth
  • 24,922
  • 4
  • 60
  • 60
  • 2
    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe. In case SystemRoot is not "C:\Windows" – Matthew Jul 13 '18 at 04:25
  • 1
    This isn't true for 32-bit PowerShell on 64-bit Windows. In that case, it is located at C:\Windows\SysWOW64\WindowsPowerShell\v1.0. – Jack Taylor Mar 25 '21 at 02:50
12

To get the complete path to the currently running PowerShell, you can use this:

[System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName

The resulting path includes the PowerShell executable filename, which allows you to distinguish between PowerShell and PowerShell ISE (unlike $PsHome, which only shows you the PowerShell folder). Also, unlike Get-Process, it is not affected by other processes running on the system, so you always get the correct path for the current architecture (32-bit or 64-bit).

The GetCurrentProcess method is available from .NET Framework 1.1 and .NET Core 1.0, so this should work on any version of .NET/PowerShell.

Jack Taylor
  • 5,588
  • 19
  • 35
0

I had a similar issue but it turned out to be an issue related to path. In my computer in Windows folder too an additional copy of powershell.exe is installed. Please check the path variable to get which .exe is called.