SuperOps.ai Agent Uninstall/Reinstall, Windows

# Determine the UninstallView download URL based on system architecture
if ([Environment]::Is64BitOperatingSystem) {
    $DownloadUrl = "https://www.nirsoft.net/utils/uninstallview-x64.zip"
} else {
    $DownloadUrl = "https://www.nirsoft.net/utils/uninstallview.zip"
}

$DestinationFolder = "$env:SystemDrive\limehawk\nirsoft"

# Create the destination folder if it doesn't exist
if (-not (Test-Path $DestinationFolder)) {
    New-Item -ItemType Directory -Path $DestinationFolder | Out-Null
}

# Download and extract the UninstallView zip file
$ZipFilePath = Join-Path $DestinationFolder "UninstallView.zip"
Write-Host "Downloading $DownloadUrl to $ZipFilePath..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipFilePath -UseBasicParsing

Write-Host "Extracting $ZipFilePath to $DestinationFolder..."
Expand-Archive -Path $ZipFilePath -DestinationPath $DestinationFolder -Force

# Uninstall the specified software using UninstallView
$UninstallProgram = "$AgentName*"
$UninstallViewPath = Join-Path $DestinationFolder "UninstallView.exe"

# Attempt to uninstall
Write-Host "Attempting to uninstall $AgentName..."
Start-Process -FilePath $UninstallViewPath -ArgumentList "/quninstallwildcard `"$UninstallProgram`" 5" -PassThru

Write-Host "Uninstall attempt completed for $AgentName. Please check manually to confirm uninstallation."

# Clean up by removing the downloaded zip file
Remove-Item $ZipFilePath -Force

Start-Sleep -Seconds 180  # Pause for 3 minutes

Invoke-Command -ScriptBlock {
    param ($url) 
    $fileName = Split-Path -Path "$url" -Leaf

    # Download the file and handle any errors
    try {
        Write-Host "Downloading file from $url..."
        Invoke-WebRequest -Uri "$url" -Outfile "$fileName"
        Write-Host "File downloaded successfully."
    } catch {
        Write-Error "Failed to download file from $url"
        Write-Error $_.Exception.Message
        exit 1
    }

    # Start the process and handle any errors
    try {
        Write-Host "Starting the installation process..."
        Start-Process -Wait -FilePath msiexec -ArgumentList "/i", "$fileName", "/qn", "LicenseAccepted=YES"
        Write-Host "Installation process completed successfully."
    } catch {
        Write-Error "Failed to start the installation process"
        Write-Error $_.Exception.Message
        exit 1
    }
} -ArgumentList "$AgentDownloadURL"

Script data

Language - PowerShell

Run as - System / Root User

Script timeout duration - 10 Mins

Script variables

Run time variables

AgentName

AgentDownloadURL

Read me

$AgentName: This variable represents the name of the agent that will be uninstalled using UninstallView. It corresponds to the name displayed in the "Add/Remove Programs" list. - $AgentDownloadURL: This variable holds the URL from which the RMM agent will be downloaded for silent installation.