Path to Powershell.exe (v 2.0)

PowershellPath

Powershell Problem Overview


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.

Powershell Solutions


Solution 1 - Powershell

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 (https://stackoverflow.com/questions/1825585/determine-what-version-of-powershell-is-installed) 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\

Solution 2 - Powershell

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 ...

Solution 3 - Powershell

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

Solution 4 - Powershell

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

Solution 5 - Powershell

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjjorasView Question on Stackoverflow
Solution 1 - PowershelldoobopView Answer on Stackoverflow
Solution 2 - PowershellSimon BView Answer on Stackoverflow
Solution 3 - PowershellNathan HartleyView Answer on Stackoverflow
Solution 4 - PowershellravikanthView Answer on Stackoverflow
Solution 5 - PowershellJack TaylorView Answer on Stackoverflow