Detection logic for PowerShell installation

Detection logic for PowerShell installation

Rate This
  • Comments 15

"How do we programmatically detect that PowerShell is installed ?" - This question has started coming up frequently as more folks (both internally and externally) have started to build applications with PowerShell support. As we approach Win7/W2K8-R2 release, which will include PowerShell 2.0 in-box, it is pertinent to have the right guidance out for PowerShell detection logic. If you're writing an installer which relies on PowerShell presence, not only do you need to detect whether PowerShell is installed, but also what version of PowerShell is installed.

  • To check if any version of PowerShell is installed, check for the following value in the registry:
    • Key Location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1
    • Value Name: Install
    • Value Type: REG_DWORD
    • Value Data: 0x00000001 (1
  • To check whether version 1.0 or 2.0 of PowerShell is installed, check for the following value in the registry:
    • Key Location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine
    • Value Name: PowerShellVersion
    • Value Type: REG_SZ
    • Value Data: <1.0 | 2.0> 


  • Depending on any other registry key(s), or version of PowerShell.exe or the location of PowerShell.exe is not guaranteed to work in the long term.
  • PowerShell 2.0 doesn't support side by side installations with 1.0, but 2.0 is back-wards compatible with 1.0.

Hemant Mahawar [MSFT]
Program Manager
Windows PowerShell

<Updated  6/26 to fix the spelling of PowerShell>

Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post
  • And what should we use to test it VBScript? LOLL

  • Did you really spell PowerShell wrong in the article title!!

  • @Daniel - thanks.  Fixed now.


    Jeffrey Snover [MSFT]

    Distinguished Engineer

    Visit the Windows PowerShell Team blog at:

    Visit the Windows PowerShell ScriptCenter at:

  • FYI, the ps installer won't set HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\Insall = 1... so if your app is 32 bit and running on 64 bit windows then this method won't work.

  • How do we detect PowerShell 2.0 (but not 1.0) in a manner that won't break when PowerShell 3.0 is released?

  • Is there a simple variable that can be used for version detection? I'm thinking of something like:

    if ( $psVersion -lt 2 )

     { 'Powershell version must be 2 or greater' }


     { 'Processing x' }

  • I see the team have addressed this in version 2 with the $psversiontable structure.

    The foillowing code should do the trick:

    if ( $psversiontable ) { 'v2+' } else { 'v1' }

  • How is PS removed from win2003? KB 139 & 141 are not found in add/remove updates and 2003-sp2 is removed but PS aritfacts remain in registry and in system32 folder.

  • How about you write a script that tells us which version of powershell to install via OS and then tries to install it. 4 tries of my OS (windows 7 64 bit) and each one gives me the 'this install is not applicable to your system' everytime.

    You know what doesn't give me this error? EVERY OTHER scripting language!

  • @cz9qvh: The method works fine. The registry key you list is not one of the ones listed above that they state to check.

  • @Ken: You check if PowerShellVersion is set to 2.0 as stated in the article above.

  • @richard semock: You can't remove it. PowerShell installs much like a hotfix and therefore can't be uninstalled. You will need to rebuild your server if you don't want it anymore.

  • @powershell makes me sad: Windows 7 comes with PowerShell 2.0 built-in. You are getting the "this install is not applicable to your system" message for a good reason. The PowerShell installer is for systems that don't come with it.

  • I get a result of PowerShellVersion : 2.0 from the following

    $regkey = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine"

    Get-ItemProperty -Path $regkey -Name PowerShellVersion

    Then I get a result of PSVersion  3.0 from the following


    and 3 0 -1 -1 from

    $host.version or (get-host).version

    So clearly I have version 3.0, but the article claims the registry key to be the only long term guarantee. Perhaps not...

  • This post appears to be inaccurate, see [1]. "For PowerShell 3.0, there appears to be a new one, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3."

    1.[] ; ; ; ; ; X.Determine installed PowerShell version - Stack Overflow ; ;

Page 1 of 1 (15 items)