Created
May 20, 2021 02:53
-
-
Save pronichkin/9d5caaf86329c3098e2a9f23d0c07bdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
AnalyticsInfo class is the documented way to track OS version. It returns | |
a string value. The format of this string is not documented, and one should | |
not rely on a certain value. Those values can only be used to tell one OS | |
version from another. | |
https://docs.microsoft.com/uwp/api | |
/windows.system.profile.analyticsversioninfo.devicefamilyversion | |
This API is not available on Server Core | |
#> | |
$AnalyticsInfo = [Windows.System.Profile.AnalyticsInfo,Windows.System.Profile,ContentType=WindowsRuntime] | |
$VersionInfo = $AnalyticsInfo.GetMember( 'get_VersionInfo' ) | |
$AnalyticsVersionInfo = $VersionInfo.Invoke( $Null, $Null ) | |
# This returns `2814751015109593` on my test machine | |
$AnalyticsVersionInfo.DeviceFamilyVersion | |
<# | |
You technically *can* parse it if you are curious of what's in this string, | |
even though you *should not* | |
https://stackoverflow.com/questions/31783604/windows-10-get-devicefamilyversion | |
#> | |
$v = [System.Int64]::Parse( $AnalyticsVersionInfo.DeviceFamilyVersion ) | |
$v1 = ( $v -band 0xFFFF000000000000l ) -shr 48 | |
$v2 = ( $v -band 0x0000FFFF00000000l ) -shr 32 | |
$v3 = ( $v -band 0x00000000FFFF0000l ) -shr 16 | |
$v4 = $v -band 0x000000000000FFFFl | |
# This returns `10.0.19043.985` on my test machine | |
[System.Version]::Parse( "$v1.$v2.$v3.$v4" ) | |
<# | |
There is *no* decoding ring published that would allow a translation | |
from any of the above values to a friendly display version such as `21H1` | |
The following alternative is only available on the latest OS versions, | |
starting with Azure Stack HCI, version 20H2 | |
#> | |
Get-ComputerInfo -Property 'osDisplayVersion' |
Всё правильно. По умолчанию выдаётся объект, чтобы с ним потом было удобно что-нибудь ещё делать. Если хотите строку, добавьте .toString()
в конец:
[System.Version]::Parse( "$v1.$v2.$v3.$v4" ).toString()
Спасибо😉👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This returns
10.0.19043.985
on my test machine ( это как? ) вот моя ( Major Minor Build Revision )