07-21-2023, 08:28 PM
PowerShell 7
================
The accepted answer is only appropriate if one version of PowerShell is installed on a computer. With the advent of PowerShell 7, this scenario becomes increasingly unlikely.
Microsoft's [documentation][1] states that additional registry keys are created when PowerShell 7 is installed:
> Beginning in PowerShell 7.1, the [installer] package creates registry keys
> that store the installation location and version of PowerShell. These
> values are located in
> `HKLM\Software\Microsoft\PowerShellCore\InstalledVersions\<GUID>`. The
> value of `<GUID>` is unique for each build type (release or preview),
> major version, and architecture.
Exploring the registry in the aforementioned location reveals the following registry value: `SemanticVersion`. This value contains the information we seek.
On my computer it appears like the following:
```none
Path Name Type Data
---- ---- ---- ----
HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions\31ab5147-9a97-4452-8443-d9709f0516e1 SemanticVersion String 7.1.3
```
[![Image displaying the specified key in the Windows Registry Editor][2]][2]
As you can see, the version of PowerShell 7 installed on my computer is 7.1.3. If PowerShell 7 is **not** installed on the target computer, the key in its entirety should not exist.
As mentioned in the Microsoft documentation, the registry path will be slightly different dependent on installed PowerShell version.
Part of the key path changing could pose a challenge in some scenarios, but for those interested in a command line-based solution, PowerShell itself can handle this problem easily.
The PowerShell cmdlet used to query the data in this registry value is the [`Get-ItemPropertyValue` cmdlet][3]. Observe its use and output as follows (note the asterisk [wildcard][4] character used in place of the part of the key path that is likely to change):
``` none
PS> Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions\*" -Name "SemanticVersion"
7.1.3
```
Just a simple one-liner.
[1]:
[3]:
================
The accepted answer is only appropriate if one version of PowerShell is installed on a computer. With the advent of PowerShell 7, this scenario becomes increasingly unlikely.
Microsoft's [documentation][1] states that additional registry keys are created when PowerShell 7 is installed:
> Beginning in PowerShell 7.1, the [installer] package creates registry keys
> that store the installation location and version of PowerShell. These
> values are located in
> `HKLM\Software\Microsoft\PowerShellCore\InstalledVersions\<GUID>`. The
> value of `<GUID>` is unique for each build type (release or preview),
> major version, and architecture.
Exploring the registry in the aforementioned location reveals the following registry value: `SemanticVersion`. This value contains the information we seek.
On my computer it appears like the following:
```none
Path Name Type Data
---- ---- ---- ----
HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions\31ab5147-9a97-4452-8443-d9709f0516e1 SemanticVersion String 7.1.3
```
[![Image displaying the specified key in the Windows Registry Editor][2]][2]
As you can see, the version of PowerShell 7 installed on my computer is 7.1.3. If PowerShell 7 is **not** installed on the target computer, the key in its entirety should not exist.
As mentioned in the Microsoft documentation, the registry path will be slightly different dependent on installed PowerShell version.
Part of the key path changing could pose a challenge in some scenarios, but for those interested in a command line-based solution, PowerShell itself can handle this problem easily.
The PowerShell cmdlet used to query the data in this registry value is the [`Get-ItemPropertyValue` cmdlet][3]. Observe its use and output as follows (note the asterisk [wildcard][4] character used in place of the part of the key path that is likely to change):
``` none
PS> Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions\*" -Name "SemanticVersion"
7.1.3
```
Just a simple one-liner.
[1]:
[To see links please register here]
[2]:[3]:
[To see links please register here]
[4]:[To see links please register here]