r/PowerShell • u/JustAnITGuyAtWork11 • 1d ago
Solved Script to resolve missing MSI Cache for google chrome (1603,1612)
Just sharing this because ive had this issue across 1500 devices and with the help of copilot this script has been generated and has been resolving the issues perfectly.
Due to missing MSI Caches, Upgrades for chrome are failing with MSI 1603 or MSI 1612. This script pulls the latest, forcefully removes the old chrome, and installs fresh
# ==========================
# Google Chrome Remediation
# ==========================
$DownloadUrl = "https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise64.msi"
$TempDir = "C:\ProgramData\ChromeRemediation"
$MSIPath = Join-Path $TempDir "GoogleChromeStandaloneEnterprise64.msi"
Write-Host "Starting Chrome remediation..."
# Ensure TLS 1.2+ is enabled for older PowerShell / Windows builds
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
# --------------------------------------------------
# Download Latest Chrome Enterprise 64-bit MSI
# --------------------------------------------------
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
Write-Host "Downloading latest Chrome Enterprise 64-bit MSI..."
try {
# Suppress progress bar to prevent severe Invoke-WebRequest slowdowns in PowerShell 5.1
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $DownloadUrl -OutFile $MSIPath -UseBasicParsing -ErrorAction Stop
}
catch {
Write-Error "Failed to download Chrome MSI: $_"
exit 1
}
# Verify the file exists and is valid (at least 50 MB to rule out HTML error pages)
if (-not (Test-Path $MSIPath) -or (Get-Item $MSIPath).Length -lt 50MB) {
Write-Error "Downloaded MSI is missing or smaller than expected. Aborting remediation."
exit 1
}
Write-Host "Download verified ($([math]::Round((Get-Item $MSIPath).Length / 1MB, 2)) MB)."
# --------------------------------------------------
# Backup bookmarks
# --------------------------------------------------
$BackupRoot = "C:\ProgramData\ChromeBookmarkBackup"
New-Item -ItemType Directory -Path $BackupRoot -Force | Out-Null
Get-ChildItem "C:\Users" -Directory -ErrorAction SilentlyContinue | ForEach-Object {
$User = $_.Name
Get-ChildItem "$($_.FullName)\AppData\Local\Google\Chrome\User Data" `
-Directory `
-ErrorAction SilentlyContinue |
ForEach-Object {
$BookmarkFile = Join-Path $_.FullName "Bookmarks"
if (Test-Path $BookmarkFile) {
$BackupName = "$User-$($_.Name)-Bookmarks.json"
Copy-Item `
$BookmarkFile `
(Join-Path $BackupRoot $BackupName) `
-Force `
-ErrorAction SilentlyContinue
Write-Host "Backed up bookmarks for $User ($($_.Name))"
}
}
}
# --------------------------------------------------
# Kill Chrome Processes
# --------------------------------------------------
Get-Process chrome,googleupdate,googleupdater `
-ErrorAction SilentlyContinue |
Stop-Process -Force
# --------------------------------------------------
# Remove Chrome Uninstall Keys
# --------------------------------------------------
$UninstallRoots = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
)
foreach ($Root in $UninstallRoots) {
Get-ChildItem $Root -ErrorAction SilentlyContinue | ForEach-Object {
$App = Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue
if ($App.DisplayName -eq "Google Chrome") {
Write-Host "Removing uninstall key $($_.PSChildName)"
Remove-Item $_.PSPath `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
}
# --------------------------------------------------
# Remove Windows Installer Product Registrations
# --------------------------------------------------
Get-ChildItem `
"Registry::HKEY_CLASSES_ROOT\Installer\Products" `
-ErrorAction SilentlyContinue |
ForEach-Object {
$Item = Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue
if ($Item.ProductName -eq "Google Chrome") {
Write-Host "Removing installer registration $($_.PSChildName)"
Remove-Item $_.PSPath `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
}
}
# --------------------------------------------------
# Remove Program Files Installs
# --------------------------------------------------
Remove-Item `
"C:\Program Files\Google\Chrome" `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
Remove-Item `
"C:\Program Files (x86)\Google\Chrome" `
-Recurse `
-Force `
-ErrorAction SilentlyContinue
# --------------------------------------------------
# Install Latest Chrome
# --------------------------------------------------
$Process = Start-Process `
msiexec.exe `
-ArgumentList "/i `"$MSIPath`" /qn /norestart" `
-Wait `
-PassThru
Write-Host "Chrome MSI exit code: $($Process.ExitCode)"
# Clean up the downloaded installer
Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue
if ($Process.ExitCode -in @(0,3010)) {
Write-Host "Chrome installation successful"
} else {
Write-Host "Chrome installation failed"
exit $Process.ExitCode
}
# --------------------------------------------------
# Validation
# --------------------------------------------------
$Chrome = Get-ItemProperty `
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, `
HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* `
-ErrorAction SilentlyContinue |
Where-Object {$_.DisplayName -eq "Google Chrome"}
if ($Chrome) {
Write-Host "Installed Version: $($Chrome.DisplayVersion)"
} else {
Write-Host "Chrome not detected after install"
exit 1}
15
Upvotes
3
u/BlackV 1d ago
Have a think about not using back ticks like that
https://get-powershellblog.blogspot.com/2017/07/bye-bye-backtick-natural-line.html
are you running this in intune (or similar)?
1
u/Advanced_Day8657 1d ago
Very cool. Chrome was unable to auto update?
1
u/gadget850 1d ago
I get issues like this where the install is in c:\windows\ccmcache and got auto cleared. The MicrosoftProgram_Install_and_Uninstall.meta.diagcab still works to clean out the registry for these issues since our Enterprise installs have the troubleshooters disabled. I have it as a Bomgar script.