Display the Windows upgrade history using PowerShell
It may sometimes be useful to look at the upgrade history of a PC running Windows. Maybe you would like to know about the first installed version of Windows on the PC, or need to look up the information for troubleshooting or analysis.
The Windows Registry holds the information under the key Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup and the information there may be all you require.
Just check the Source OS key and browse the data stored under each key to find out about previously installed versions and editions of Windows.
Information that is revealed to you when you browse a Source OS key in the Registry includes the operating system's product name, registered owner and installation path, build number, and installation date among others.
You may use PowerShell commands to list core information. It is just another option to display the Windows upgrade history.
Using PowerShell
You need to open a PowerShell prompt to run the commands. Note that you don't need elevated privileges for that:
- Tap on the Windows-key, type powershell and select the program from the list of results.
With PowerShell open, run the following commands using copy and paste.
Command 1: $AllBuilds = $(gci "HKLM:\System\Setup" | ? {$_.Name -match "\\Source\s"}) | % { $_ | Select @{n="UpdateTime";e={if ($_.Name -match "Updated\son\s(\d{1,2}\/\d{1,2}\/\d{4}\s\d{2}:\d{2}:\d{2})\)$") {[dateTime]::Parse($Matches[1],([Globalization.CultureInfo]::CreateSpecificCulture('en-US')))}}}, @{n="ReleaseID";e={$_.GetValue("ReleaseID")}},@{n="Branch";e={$_.GetValue("BuildBranch")}},@{n="Build";e={$_.GetValue("CurrentBuild")}},@{n="ProductName";e={$_.GetValue("ProductName")}},@{n="InstallTime";e={[datetime]::FromFileTime($_.GetValue("InstallTime"))}} };
Command 2:Â $AllBuilds | Sort UpdateTime | ft UpdateTime, ReleaseID, Branch, Build, ProductName
PowerShell returns previous Windows versions in a table when you execute the second command. If you run Windows 10, you may get various Windows 10 feature updates builds returned to you.
If the machine was update from a previous version of Windows, you get its product name listed there as well.
The information may be useful. You can find out if the system was upgraded from a previous version of Windows, or which feature updates of Windows 10 were installed on it prior to the one that is installed currently on the device.
You could verify that the PC you bought was not upgrade from a previous version of Windows but clean-installed.
Now You: What happens when you run the script on your Windows machine? (via Deskmodder)
Related articles
- Get File hashes using Windows PowerShell
- Learn PowerShell, using PowerShell
- PowerShell vs. PowerShell Core, what you need to know
- Use PowerShell to manage Scheduled Tasks in Windows
- Use Windows PowerShell to install optional features
My Windows 7 SP1 doesn’t have an entry for :
HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS.
Powershell is another BIG mistake of MÄ°crosoft , VBS is much more userfriendly and Efficient
1. VBScript is “lighter” than PowerShell. It utilizes less memory and is generally “faster” than PowerShell at doing the same tasks
2. To Manage Computers that Can’t Run PowerShell you must use vbs
3. On Windows XP and Windows Server 2003 , PowerShell needs to be installed as part of the Windows Management Framework 2.0
4.Microsoft has not allowed PowerShell to run inside of an MSI file, so admins are still forced to use VBScript
Et. Unfortunatelly I must say this : Satya Nadella has no talent to be a Ceo
Stop live in the past. And RTFM Please https://docs.microsoft.com/en-us/windows/msix/psf/run-scripts-with-package-support-framework
A great example of a non sequitur.
No argument with the good points 1 to 4.
But a CEO must focus on things well beyond tools that the most technically adept would prefer to use, unless, of course, that is precisely the market they are primarily focused on. MS is not.
Nadella is shifting focus away from the operating system – seems smart given MS’ failures to foresee and leverage the overall move towards mobile.
MS no longer dominates – ceding major ground to mostly Google / Alphabet. Windows may well become irrelevant in 10 to 15 years.
code above is very ugly only because of the pain in the ass parsing of the install, which is in hexadecimal format
powershell is very user friendly, you probably don’t see it because you don’t understand it or haven’t worked with any object oriented language
OR
$Session = New-Object -ComObject “Microsoft.Update.Session”
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$s = $Searcher.QueryHistory(0, $historyCount)
[psobject[]]$out = @()
foreach ($obj in $s)
{
$title = $obj.Title
$t1 = $title | select-string “\(.+\)” | Select-Object -ExpandProperty Matches | Select-Object -ExpandProperty value
$ErrorActionPreference = “SilentlyContinue”
$t2 = $t1.Replace(“(“,””)
$id = $t2.Replace(“)”,””)
$ErrorActionPreference = “Continue”
$psObj = New-Object PSObject
$psObj | Add-Member -Name ID -MemberType Noteproperty -Value $id
$psObj | Add-Member -Name Title -MemberType NoteProperty -Value $obj.Title
$psObj | Add-Member -Name Date -MemberType NoteProperty -Value $obj.Date
$out += $psObj
}
$out | Format-Table
What happens when you run the script on your Windows machine?
—
FWIW, This is W7 Pro on an ASUS Pro box bought in February 2015.
Using the PowerShell commands, I get the following return each time:
PS C:\Windows\System32\WindowsPowerShell\v1.0>
In the registry under SetupCI there is only one folder named PendingRequest with the following information:
NAME: Default TYPE: REGÂ_SZ DATE:
(value not set)
I have no idea what this means.
Nothing appear on my Win 7 Ultimate x32
Precisely, nothing, on a fresh install of 7: imgur.com/l3IpWZr
Would have been nice a message there “yay, your OS is clean”. Since it returned no errors I assume the command worked.
Me too. The first thing I do when I install my Windows 7 is to disable Windows Update, remove all updates, including Internet Explorer and returning it to version 8.
That’s just horrible. Security updates are there for a reason.
And this is why we have forced updated in Windows 10.
Powershell, although powerful, not user friendly
Exactly this. I do not understand why this year so many sites advice the use of ths tool. It is not even for the average user.