Hi everybody,
here is a small one-liner to find out what Windows 10 builds a machine ran in the past and when it was upgraded to which build.
You can call it the improved version of my earlier blog post regarding this topic.
Update: thank you Timo for pointing out that the build output might have been unsorted. New script below takes care of that.
This is the PowerShell code that grabs the information:
$winBuilds = @{}
$regKeys = Get-ChildItem -Path 'HKLM:\SYSTEM\Setup' | Where-Object -FilterScript {($_.Name -like '*Source OS *')}
foreach($uKey in $regKeys)
{
$winBuilds.Add((Get-ItemProperty -Path $uKey.PSPath -Name ReleaseId).ReleaseId,(Get-ItemProperty -Path $uKey.PSPath -Name InstallDate).InstallDate)
}
$winBuilds.Add((Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId).ReleaseId,(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name InstallDate).InstallDate)
foreach($item in $winBuilds.GetEnumerator() | Sort Name)
{
Write-Host "Build $($item.Name) - $([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($item.Value)))"
}
To grab this as a custom inventory field in your KACE SMA it can be melted down to:
ShellCommandTextReturn(%windir%\SysNative\WindowsPowerShell\v1.0\powershell -NoLogo -NonInteractive -NoProfile -command "$winBuilds = @{};Get-ChildItem -Path 'HKLM:\SYSTEM\Setup' | Where-Object -FilterScript {($_.Name -like '*Source OS *')}|foreach-object -process {$winBuilds.Add((Get-ItemProperty -Path $_.PSPath -Name ReleaseId).ReleaseId,(Get-ItemProperty -Path $_.PSPath -Name InstallDate).InstallDate)};$winBuilds.Add((Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId).ReleaseId,(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name InstallDate).InstallDate);foreach($item in $winBuilds.GetEnumerator() | Sort Name){Write-Host "Build $($item.Name) - $([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($item.Value)))"}")
Be sure to use the SysNative-call of powershell.exe to avoid problems with the KACE agents 32/64-bit-view-of-things!
Comments