Welcome to MSDN Blogs Sign in | Join | Help

Detection logic for PowerShell installation

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

Remember: 

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

Published Thursday, June 25, 2009 11:16 AM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Detection logic for PoweShell installation

And what should we use to test it VBScript? LOLL

Thursday, June 25, 2009 10:30 AM by Pter

# re: Detection logic for PoweShell installation

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

Friday, June 26, 2009 3:28 AM by Daniel

# re: Detection logic for PowerShell installation

@Daniel - thanks.  Fixed now.

Enjoy!

Jeffrey Snover [MSFT]

Distinguished Engineer

Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Friday, June 26, 2009 8:46 AM by PowerShellTeam

# re: Detection logic for PowerShell installation

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.

Monday, July 06, 2009 12:39 PM by cz9qvh

# re: Detection logic for PowerShell installation

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

Saturday, October 10, 2009 3:34 AM by Ken

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker