Skip to content

Instantly share code, notes, and snippets.

@pronichkin
Created May 20, 2021 02:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pronichkin/9d5caaf86329c3098e2a9f23d0c07bdd to your computer and use it in GitHub Desktop.
Save pronichkin/9d5caaf86329c3098e2a9f23d0c07bdd to your computer and use it in GitHub Desktop.
<#
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'
@samardack
Copy link

This returns 10.0.19043.985 on my test machine ( это как? ) вот моя ( Major Minor Build Revision )

                                                                                                                        -----  -----  -----  --------
                                                                                                                      (    10     0      19042  985   ) 

@pronichkin
Copy link
Author

Всё правильно. По умолчанию выдаётся объект, чтобы с ним потом было удобно что-нибудь ещё делать. Если хотите строку, добавьте .toString() в конец:

[System.Version]::Parse( "$v1.$v2.$v3.$v4" ).toString()

@samardack
Copy link

Спасибо😉👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment