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>
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]
<Updated 6/26 to fix the spelling of PowerShell>