Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Last active August 9, 2024 19:18
Show Gist options
  • Save jwmoss/ee62a015a8e1b25c4e09dfedb86e7715 to your computer and use it in GitHub Desktop.
Save jwmoss/ee62a015a8e1b25c4e09dfedb86e7715 to your computer and use it in GitHub Desktop.
afaddin
# Define the software to uninstall and the new software to install
$softwareToUninstall = "AdvanceFlow Addin"
$newSoftwareInstallerPath = "./ps1"
$newSoftwareInstallArguments = "/i /qn"
# Function to uninstall the old software
function Uninstall-Software {
param (
[string]$softwareName
)
## FIND WHERE THE ADDIN IS
$uninstallString = (Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object { $_.DisplayName -like "*$softwareName*" }).UninstallString
if ($uninstallString) {
Write-Host "Uninstalling $softwareName..."
Start-Process -FilePath "cmd.exe" -ArgumentList "/c", $uninstallString, "/quiet" -Wait
Write-Host "$softwareName uninstalled successfully."
} else {
Write-Host "$softwareName not found."
}
}
# Function to install the new software
function Install-Software {
param (
[string]$installerPath,
[string]$installArguments
)
if (Test-Path $installerPath) {
Write-Host "Installing new software..."
$process = Start-Process -FilePath $installerPath -ArgumentList $installArguments -Wait -PassThru
switch ($process.ExitCode) {
0 {
Write-Host "New software installed successfully."
}
3010 {
Write-Host "New software installed successfully. Please reboot to apply changes."
}
Default {
Write-Host "New software installation unknown status with exit code $($process.ExitCode)."
}
}
} else {
Write-Host "Installer not found at $installerPath."
}
}
# Uninstall the old software
Uninstall-Software -softwareName $softwareToUninstall
# Install the new software
Install-Software -installerPath $newSoftwareInstallerPath -installArguments $newSoftwareInstallArguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment