24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

powershell で .NET Framework のバージョンを確認

Last updated at Posted at 2015-10-27

powershell のバージョン

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34209
BuildVersion                   6.3.9600.17400
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

.NET Framework 4 系のみですが以下のレジストリから情報を取得できます。

PS C:\> get-item 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'


    Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4


Name                           Property
----                           --------
Full                           Version       : 4.5.51650
                               CBS           : 1
                               TargetVersion : 4.0.0
                               Install       : 1
                               InstallPath   : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
                               Servicing     : 0
                               Release       : 379893

Release 番号からバージョンを参照します。
Release 番号についてはこちら

switch 文にすると簡単かなと。

$release = (get-item 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').GetValue("Release")

switch -Exact ($release)
{
    "378389" { Write-Host ".NET Framework 4.5" }
    "378675" { Write-Host ".NET Framework 4.5.1 on Windows 8.1" }
    "378758" { Write-Host ".NET Framework 4.5.1 on Windows vista/7/8" }
    "379893" { Write-Host ".NET Framework 4.5.2" }
    "393295" { Write-Host ".NET Framework 4.6 on Windows 10" }
    "393297" { Write-Host ".NET Framework 4.6" }
    "394254" { Write-Host ".NET Framework 4.6.1 on Windows 10" }
    "394271" { Write-Host ".NET Framework 4.6.1" }
    "394802" { Write-Host ".NET Framework 4.6.2 on Windows 10" }
    "394806" { Write-Host ".NET Framework 4.6.2" }
    "460798" { Write-Host ".NET Framework 4.7 on Windows 10" }
    "460805" { Write-Host ".NET Framework 4.7" }
    "461308" { Write-Host ".NET Framework 4.7.1 on Windows 10" }
    "461310" { Write-Host ".NET Framework 4.7.1" }
    "461808" { Write-Host ".NET Framework 4.7.2 on Windows 10" }
    "461814" { Write-Host ".NET Framework 4.7.2" }
    "528040" { Write-Host ".NET Framework 4.8 on Windows 10" }
    "528049" { Write-Host ".NET Framework 4.8" } 
    default { Write-Host "Unknown version" }
}
24
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?