85 lines
3.7 KiB
PowerShell
85 lines
3.7 KiB
PowerShell
|
|
<#
|
||
|
|
Author: Gabe Kerntke
|
||
|
|
Date: 02-07-2025
|
||
|
|
|
||
|
|
.Synopsis
|
||
|
|
Script checks if Chrome is installed and then reinstalls it while also deleting each users appdata folder
|
||
|
|
|
||
|
|
.Modified
|
||
|
|
2025-02-07 (GabeK) - Original script created
|
||
|
|
2025-05-21 (GabeK) - updated to use functions script
|
||
|
|
|
||
|
|
#>
|
||
|
|
|
||
|
|
# Variables #
|
||
|
|
|
||
|
|
$App_Name = "Chrome"
|
||
|
|
$File_Name_Prefix = "Chrome-x64"
|
||
|
|
$File_Name_Extension = "exe"
|
||
|
|
$Install_Parameters = "/silent /install"
|
||
|
|
$EPCache_Folder = "3rd Party Patches\$App_Name"
|
||
|
|
$Version_URL = "https://versionhistory.googleapis.com/v1/chrome/platforms/win64/channels/stable/versions"
|
||
|
|
$Online_Version = Invoke-RestMethod $Version_URL | Select-Object -ExpandProperty versions | Select-Object -ExpandProperty version | Select-Object -First 1
|
||
|
|
$DownloadURL = "https://dl.google.com/chrome/install/latest/chrome_installer.exe"
|
||
|
|
$File_Name = "$File_Name_Prefix-$Online_Version.$File_Name_Extension"
|
||
|
|
$User_Folder = "C:\Users\$($User)\AppData\Local\Google\Chrome"
|
||
|
|
$User_Folder2 = "C:\Users\$($User)\AppData\Roaming\Google\Chrome"
|
||
|
|
$Program_Folder = "C:\Program Files\Google"
|
||
|
|
$Program_Folder2 = "C:\Program Files (x86)\Google"
|
||
|
|
|
||
|
|
# Functions #
|
||
|
|
|
||
|
|
Function Uninstall-App {
|
||
|
|
Start-Process "C:\Program Files\Google\Chrome\Application\*\Installer\setup.exe" -ArgumentList "--uninstall --multi-install --chrome --system-level --force-uninstall" -ErrorAction SilentlyContinue
|
||
|
|
Start-Sleep 15
|
||
|
|
If (Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }) {
|
||
|
|
Write-Host "Failed to uninstall $App_Name via setup.exe"
|
||
|
|
|
||
|
|
$UninstallString = (Get-Software | Where-Object {$_ -like "*$App_Name*"}).UninstallString
|
||
|
|
If ($UninstallString -like "*MsiExec.exe*") { $UninstallString + " /silent" | cmd }
|
||
|
|
|
||
|
|
Elseif ($UninstallString.Substring(0, $UninstallString.Length - 17) -like "*setup.exe*") { cmd.exe /c "$UninstallString + --multi-install --chrome --force-uninstall" | Out-Null }
|
||
|
|
Start-Sleep 15
|
||
|
|
|
||
|
|
If (Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }) {
|
||
|
|
Write-Host "Failed to uninstall $App_Name via uninstall string"
|
||
|
|
Uninstall-App_WMIobject
|
||
|
|
}
|
||
|
|
Else { Write-Host "$App_Name uninstalled successfully" }
|
||
|
|
}
|
||
|
|
Else { Uninstall-App2 }
|
||
|
|
}
|
||
|
|
|
||
|
|
Function Uninstall-App2 {
|
||
|
|
$CMD = Test-Path "C:\Program Files (x86)\Google\GoogleUpdater\*\uninstall.cmd" -ErrorAction SilentlyContinue
|
||
|
|
If ($CMD -eq $true) { Start-Process -ErrorAction SilentlyContinue "C:\Program Files (x86)\Google\GoogleUpdater\*\uninstall.cmd" | Out-Null }
|
||
|
|
Start-Sleep 900
|
||
|
|
(Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }).PSPath | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue
|
||
|
|
|
||
|
|
If (Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }) {
|
||
|
|
Write-Host "Failed to uninstall $App_Name via uninstall.cmd"
|
||
|
|
Exit
|
||
|
|
}
|
||
|
|
Else { Write-Host "$App_Name uninstalled successfully" }
|
||
|
|
}
|
||
|
|
|
||
|
|
#Region Script Start
|
||
|
|
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
|
||
|
|
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
|
||
|
|
. "C:\Temp\Script Cache\Functions.ps1"
|
||
|
|
|
||
|
|
#Check to see if program is installed
|
||
|
|
$Applist = Get-Software | Sort-Object -Descending
|
||
|
|
|
||
|
|
If ($Applist.DisplayName -like "*$App_Name*") {
|
||
|
|
Close-App
|
||
|
|
Uninstall-App
|
||
|
|
Remove-User_Folder
|
||
|
|
Remove-Program_Folder
|
||
|
|
Remove-Program_Folder-ALT
|
||
|
|
Test-Probe_Online
|
||
|
|
Install-App
|
||
|
|
}
|
||
|
|
|
||
|
|
Else { Write-Host "$App_Name is not installed, exiting script." }
|
||
|
|
#Region Script End
|