Monday, February 10, 2025

Two simple PS scripts to track Windows 10 -> 11 upgrade removing applications

 TBH we have not found any yet, but as a part of a 4000 computer fleet we need to know if any are. So two simple scripts that show changes, PRE upgrade and POST upgrade.

Just put the files in C:\TEMP.

PRE

 # Run this script on Windows 10 before upgrading  
 
$computerInfo = @{  
    Name   = (Get-WmiObject Win32_ComputerSystem).Name  
    Type   = (Get-WmiObject Win32_ComputerSystem).SystemType  
    Serial = (Get-WmiObject Win32_BIOS).SerialNumber  
}  
 
$installedPrograms = Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |  
    Select-Object DisplayName, DisplayVersion, Publisher |  
    Where-Object { $_.DisplayName -ne $null -and $_.DisplayName -ne "" }  
 
$result = @{  
    ComputerInfo = $computerInfo  
    InstalledPrograms = $installedPrograms  
}  
 
$jsonResult = $result | ConvertTo-Json -Depth 4  
 
Set-Content -Path "C:\temp\Windows10.json" -Value $jsonResult  
Write-Host "Done for $($computerInfo.Name)"  

POST 

# Load previous details from JSON  
$previousDetails = $null
$previousDetails = Get-Content -Path "C:\temp\Windows10.json" | ConvertFrom-Json  
#  $previousDetails.InstalledPrograms[5].DisplayName

# Extract previous installed programs  
$previousPrograms = $previousDetails.InstalledPrograms  
write-host $previousDetails.InstalledPrograms.Count "Applications detected"  -ForegroundColor Green  
 


  # Output loaded JSON for debugging  
Write-Host "Loaded JSON content:"  
Write-Output ($previousDetails | ConvertTo-Json -Depth 4)  

# Extract computer information  
$previousComputerInfo = $previousDetails.ComputerInfo  
$serialNumber = $previousComputerInfo.Serial  
$computerName = $previousComputerInfo.Name  
$computerType = $previousComputerInfo.Type  
 
# Get current computer details  
$newName = (Get-WmiObject Win32_ComputerSystem).Name  
$newType = (Get-WmiObject Win32_ComputerSystem).SystemType  
$newSerial = (Get-WmiObject Win32_BIOS).SerialNumber  
 
# Print and compare computer details  
Write-Output "Comparing Computer Details:"  
 
if ($computerName -ne $newName) {  
    Write-Host "Name has changed: $computerName -> $newName"  
} else {  
    Write-Host "Name check pass: $newName" -ForegroundColor Green  
}  
 
if ($computerType -ne $newType) {  
    Write-Host "Type has changed: $computerType -> $newType"  
} else {  
    Write-Host "Type check pass: $newType" -ForegroundColor Green
}  
 
if ($serialNumber -ne $newSerial) {  
    Write-Host "Serial has changed: $serialNumber -> $newSerial"  
} else {  
    Write-Host "Serial number check pass: $newSerial"  -ForegroundColor Green
}  
 
 # $previousDetails.InstalledPrograms.Count


 
# Create a hashtable for quick lookup of previous program versions  
$previousProgramVersions = @{}  
foreach ($program in $previousPrograms) {  
    if ($program.DisplayName -ne $null) {  
        $previousProgramVersions[$program.DisplayName] = $program.DisplayVersion  
    }  }  
 
# Get current list of installed programs  
$currentInstalledPrograms = Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |  
    Select-Object DisplayName, DisplayVersion, Publisher |  
    Where-Object { $_.DisplayName -ne $null -and $_.DisplayName -ne "" }  
 
# Compare programs  
Write-Output "Comparing Installed Programs:"  
foreach ($currentProgram in $currentInstalledPrograms) {  
    $currentName = $currentProgram.DisplayName  
    $currentVersion = $currentProgram.DisplayVersion  
 
    if ($currentName -ne $null -and $previousProgramVersions.ContainsKey($currentName)) {  
        $previousVersion = $previousProgramVersions[$currentName]  
        if ($previousVersion -eq $currentVersion) {  
            Write-host "$currentName has the same version: $currentVersion"   -ForegroundColor Green  
        } else {  
            Write-host "$currentName has changed versions: OLD=$previousVersion, NEW=$currentVersion"   -ForegroundColor yellow  
        }  
    } elseif ($currentName -ne $null) {  
        Write-host "$currentName is a new APP in the AFTER state with version: $currentVersion"   -ForegroundColor Red  
    }  }  
 
# Identify programs that were removed or missing in the current list  
$removedPrograms = $previousProgramVersions.Keys | Where-Object { -not ($currentInstalledPrograms | Select-Object -ExpandProperty DisplayName) -contains $_ }  
foreach ($removedProgram in $removedPrograms) {  
    Write-host "Program '$removedProgram' was installed before but is now removed or missing."  


Example Output

 

No comments:

Blog Archive