Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
18
Help us understand the problem. What is going on with this article?
@satoshi_iwashita

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

More than 1 year has passed since last update.

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" }
}
18
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
18
Help us understand the problem. What is going on with this article?