Help us understand the problem. What is going on with this article?

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

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" }
}
sansan
法人向け名刺管理サービスSansan及び個人向け名刺管理サービスEightを企画・開発・販売するベンチャー
http://jp.corp-sansan.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした