Reading Operating System Details

by May 28, 2020

PowerShell can easily retrieve important operating system details such as the build number and version by reading the appropriate registry values:

# read operating system info
Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion' |
# pick selected properties
Select-Object -Property CurrentBuild,CurrentVersion,ProductId, ReleaseID, UBR

Some of these values use crypting formats, though. The InstallTime registry key, for example, is just a very large integer.

 
PS> $key = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
PS> (Get-ItemProperty -Path $key).InstallTime

132119809618946052  
 

As it turns out, these are the ticks, and by using the [DateTime] type and its FromFileTime() static method, you can easily convert ticks to a meaningful install date:

 
PS> $key = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
PS> $ticks = (Get-ItemProperty -Path $key).InstallTime
PS> $date = [DateTime]::FromFileTime($ticks)
PS> "Your OS Install Date: $date"

Your OS Install Date: 09/03/2019 12:42:41  
 

You can use FromFileTime() whenever you encounter ticks. The Active Directory, for example, stores Dates in this format, too.


Twitter This Tip! ReTweet this Tip!