agent: |
fQuIFgViAbooAb7ITxZbRollout Upgrade for latest version of OpenVPN Connect to the client machine and uninstall older OpenVPN Connect/GUI versions (Powershell)
Rollout Upgrade for latest version of OpenVPN Connect to the client machine and uninstall older OpenVPN Connect/GUI versions (Powershell)
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
inputs
outputs
# PowerShell script to rollout upgrade for the latest version of OpenVPN Connect on a Windows client
# Define the URL for the latest OpenVPN Connect Client for Windows (x64)
$openVPNUrl = "https://openvpn.net/downloads/openvpn-connect-v3-windows.msi"
$installerPath = "$env:TEMP\openvpn-connect-latest.msi"
$openVPNInstallPath = "C:\Program Files\OpenVPN"
$openVPNGUIPath = "$openVPNInstallPath\bin\openvpn-gui.exe"
$uninstallerPath = "$openVPNInstallPath\Uninstall.exe"
# Function to uninstall a program by name
function Uninstall-Program($programName) {
$programs = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match $programName }
if ($programs) {
foreach ($program in $programs) {
$context.ctxprint("Uninstalling $($program.Name)...")
$program.Uninstall() | Out-Null
$context.ctxprint("$($program.Name) has been uninstalled.")
}
} else {
$context.ctxprint("$programName is not installed.")
}
}
# Terminate the OpenVPN GUI if it is running
$context.ctxprint("Checking if OpenVPN GUI is running...")
$openVPNProcess = Get-Process -Name "openvpn-gui" -ErrorAction SilentlyContinue
if ($openVPNProcess) {
$context.ctxprint("OpenVPN GUI is running. Attempting to terminate the process...")
Stop-Process -Name "openvpn-gui" -Force
Start-Sleep -Seconds 5 # Wait for 5 seconds to ensure the process has been terminated
$context.ctxprint("OpenVPN GUI process has been terminated.")
} else {
$context.ctxprint("OpenVPN GUI is not running.")
}
# Download the latest installer
$context.ctxprint("Downloading the latest OpenVPN Connect client installer...")
try {
File-Download -source $openVPNUrl -destination $installerPath
$context.ctxprint("Installer downloaded successfully.")
} catch {
$context.ctxprint("Failed to download the installer. Exiting.")
exit 1
}
# Uninstall OpenVPN Connect if it is installed
Uninstall-Program("OpenVPN Connect*")
# Check if OpenVPN GUI is installed by looking for openvpn-gui.exe
if (Test-Path $openVPNGUIPath) {
$context.ctxprint("OpenVPN GUI detected. Attempting to uninstall...")
# Uninstall OpenVPN GUI using the Uninstall.exe if it exists
if (Test-Path $uninstallerPath) {
Start-Process -FilePath $uninstallerPath -ArgumentList "/S" -Wait
$context.ctxprint("OpenVPN GUI has been uninstalled.")
} else {
$context.ctxprint("Uninstaller not found for OpenVPN GUI, please uninstall it manually.")
}
} else {
$context.ctxprint("OpenVPN GUI is not installed.")
}
# Install the new version of OpenVPN Connect
$context.ctxprint("Installing the latest version of OpenVPN Connect...")
Start-Process msiexec.exe -ArgumentList "/i `"$installerPath`" /quiet /norestart" -Wait
# Cleanup downloaded installer file
Remove-Item -Path $installerPath -Force
# Verify installation
$openVPNInstalled = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "OpenVPN Connect*" }
if ($openVPNInstalled) {
$context.ctxprint("OpenVPN Connect has been successfully updated to the latest version.")
} else {
$context.ctxprint("OpenVPN Connect installation failed.")
}
copied