Skip to content

bouatom/v1es-uninstall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

V1ES Uninstaller Script

A PowerShell script for automated uninstallation of V1ES software by downloading the uninstaller tool from an S3 bucket and executing it with SYSTEM privileges via Windows Task Scheduler.

🎯 Overview

This script automates the uninstallation process of V1ES software by:

  1. Downloading the V1ES uninstaller tool from an S3 bucket
  2. Extracting the tool to a temporary directory
  3. Creating a Windows Scheduled Task to run the uninstaller with SYSTEM privileges
  4. Monitoring the uninstallation process
  5. Displaying relevant log files
  6. Returning appropriate exit codes

The script is designed to run non-interactively and can be executed remotely or via deployment tools.

✨ Features

  • Automated Download: Downloads uninstaller from S3 with TLS 1.2 support
  • Resilient Download: Uses BITS (Background Intelligent Transfer Service) with fallback to Invoke-WebRequest
  • System Privileges: Executes uninstaller with NT AUTHORITY\SYSTEM account for maximum compatibility
  • Progress Monitoring: Monitors task execution with configurable timeout
  • Log Display: Automatically displays relevant log files after execution
  • Error Handling: Comprehensive error handling with clear error messages
  • Non-Interactive: Designed for automated deployment scenarios
  • Cleanup: Automatically removes scheduled tasks after execution

πŸ”§ Prerequisites

  • PowerShell 3.0 or higher (Windows PowerShell 5.1 or PowerShell Core 7+)
  • Administrator privileges (required for creating scheduled tasks)
  • Network access to the S3 bucket URL
  • TLS 1.2 support (automatically configured by the script)

☁️ S3 Bucket Configuration

Important Notes

⚠️ Before using this script, you must configure your S3 bucket:

  1. Upload the V1ES Uninstaller Tool to your S3 bucket

    • The tool should be packaged as a ZIP file
    • The ZIP should contain V1ESUninstallTool.exe (or a compatible executable)
  2. Configure S3 Bucket Permissions

    • Ensure the bucket allows public read access, OR
    • Configure appropriate IAM policies for authenticated access
    • Consider using pre-signed URLs for temporary access
  3. Update the Script

    • Replace the placeholder S3 URL in the script parameters with your actual S3 bucket URL
    • Format: https://your-bucket-name.s3.region.amazonaws.com/path/to/V1ESUninstallTool.zip

S3 URL Format

https://[bucket-name].s3.[region].amazonaws.com/[path]/[filename].zip

Example:

https://my-uninstaller-bucket.s3.us-east-1.amazonaws.com/tools/V1ESUninstallTool.zip

Security Best Practices

  • Use private S3 buckets with IAM policies when possible
  • Consider using pre-signed URLs for temporary access
  • Enable S3 bucket versioning to track changes
  • Use CloudFront for additional security and performance
  • Enable S3 access logging for audit trails

πŸ“– Usage

Basic Usage

.\uninstall.ps1

With Custom S3 URL

.\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/path/to/tool.zip"

With Custom Extraction Path

.\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/tool.zip" -V1ESUninstPath "D:\Temp\V1ESUninstall\"

Running as Administrator

# Right-click PowerShell and select "Run as Administrator"
.\uninstall.ps1

Running via Remote Execution

Invoke-Command -ComputerName "RemotePC" -ScriptBlock {
    Set-Location "C:\Scripts"
    .\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/tool.zip"
}

πŸ“ Parameters

Parameter Type Default Description
S3Url string "https://your-bucket.s3.region.amazonaws.com/V1ESUninstallTool.zip" URL to the V1ES uninstaller ZIP file in S3
V1ESUninstPath string "C:\Windows\Temp\V1ESUninstall\" Directory path where the uninstaller will be extracted

Parameter Examples

# Use default S3 URL (must be configured in script)
.\uninstall.ps1

# Specify custom S3 URL
.\uninstall.ps1 -S3Url "https://my-bucket.s3.us-west-2.amazonaws.com/uninstaller.zip"

# Specify both parameters
.\uninstall.ps1 -S3Url "https://my-bucket.s3.us-west-2.amazonaws.com/uninstaller.zip" -V1ESUninstPath "D:\Temp\Uninstall"

πŸ”„ How It Works

Step-by-Step Process

  1. TLS Configuration

    • Enables TLS 1.2 for secure S3 communication
  2. Download Phase

    • Downloads the uninstaller ZIP from S3
    • Uses BITS (preferred) or Invoke-WebRequest (fallback)
    • Validates download completion
  3. Extraction Phase

    • Extracts ZIP to temporary directory
    • Supports both PowerShell 5+ and older versions
    • Locates the executable (V1ESUninstallTool.exe or first .exe found)
  4. Task Creation

    • Removes any existing task with the same name
    • Creates a scheduled task with SYSTEM privileges
    • Configures task to run silently (/qn argument)
  5. Execution Phase

    • Starts the scheduled task immediately
    • Monitors task status every 15 seconds
    • Maximum wait time: 150 seconds (2.5 minutes)
    • Note: Comment indicates 60 minutes, but code uses 150 seconds
  6. Logging Phase

    • Displays relevant log files (last 80 lines each)
    • Checks multiple log file locations
  7. Cleanup Phase

    • Removes the scheduled task
    • Returns appropriate exit code

Scheduled Task Configuration

  • User: NT AUTHORITY\SYSTEM
  • Run Level: Highest (Administrator)
  • Arguments: /qn (quiet mode, no user interaction)
  • Execution Time Limit: 2 hours
  • Battery: Allowed to run on battery, won't stop if going on battery

🚦 Exit Codes

Code Meaning Description
0 Success Uninstallation completed successfully
1 Error Failed during download, extraction, or task creation
2 Partial Failure Task executed but did not return success code

Exit Code Examples

# Check exit code
.\uninstall.ps1
if ($LASTEXITCODE -eq 0) {
    Write-Host "Uninstall successful"
} else {
    Write-Host "Uninstall failed with code: $LASTEXITCODE"
}

πŸ“Š Logging

Log Files Checked

The script automatically displays the last 80 lines of the following log files (if they exist):

  1. C:\Windows\Temp\V1ESUninst\V1ESUninstallTool.log
  2. C:\Windows\Temp\V1ESUninst\ComUnist.log
  3. C:\Windows\Temp\V1ESUninst\Log_CUT.log
  4. C:\Windows\Temp\V1ESUninst\DSA_CUT.log
  5. C:\Windows\Temp\XBCUninstaller.log

Viewing Logs Manually

# View specific log
Get-Content "C:\Windows\Temp\V1ESUninst\V1ESUninstallTool.log" -Tail 100

# View all logs
Get-ChildItem "C:\Windows\Temp\V1ESUninst\*.log" | ForEach-Object {
    Write-Host "`n===== $($_.Name) ====="
    Get-Content $_.FullName -Tail 50
}

πŸ” Troubleshooting

Common Issues

1. Download Fails

Error: ERROR: Failed to download from S3

Solutions:

  • Verify S3 URL is correct and accessible
  • Check network connectivity
  • Verify S3 bucket permissions
  • Ensure TLS 1.2 is supported
  • Try accessing the URL in a browser
# Test S3 URL accessibility
Invoke-WebRequest -Uri "https://your-bucket.s3.region.amazonaws.com/tool.zip" -Method Head

2. Permission Denied

Error: ERROR: Cannot create directory or ERROR: Failed to create scheduled task

Solutions:

  • Run PowerShell as Administrator
  • Verify user has "Create Scheduled Tasks" permission
  • Check Group Policy restrictions
# Check if running as admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
Write-Host "Running as Admin: $isAdmin"

3. Executable Not Found

Error: ERROR: No EXE found in directory

Solutions:

  • Verify ZIP file contains an executable
  • Check if executable name matches V1ESUninstallTool.exe
  • Verify extraction completed successfully
  • Check file listing in extraction directory
# List extracted files
Get-ChildItem "C:\Windows\Temp\V1ESUninstall\" -Recurse

4. Task Execution Timeout

Warning: WARNING: Maximum wait time reached

Solutions:

  • Uninstallation may still be running in background
  • Check Task Scheduler for task status
  • Review log files for progress
  • Increase $maxWaitTime if needed (currently 150 seconds)
# Check task status manually
Get-ScheduledTask -TaskName "V1ES Uninstall Task" -ErrorAction SilentlyContinue
Get-ScheduledTaskInfo -TaskName "V1ES Uninstall Task" -ErrorAction SilentlyContinue

5. Extraction Fails

Error: ERROR extracting archive

Solutions:

  • Verify ZIP file is not corrupted
  • Check available disk space
  • Verify write permissions to temp directory
  • Try manual extraction to test
# Test manual extraction
Expand-Archive -Path "C:\Windows\Temp\V1ESUninstallTool.zip" -DestinationPath "C:\Test\"

Debug Mode

To enable more verbose output, modify the script to include $VerbosePreference = "Continue" at the beginning:

$VerbosePreference = "Continue"
.\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/tool.zip"

πŸ”’ Security Considerations

Security Best Practices

  1. S3 Access

    • Use private S3 buckets with IAM policies
    • Consider pre-signed URLs for temporary access
    • Enable S3 bucket encryption
    • Use CloudFront for additional security layers
  2. Script Execution

    • Verify script integrity before execution
    • Use code signing for production deployments
    • Restrict script execution via Group Policy if needed
  3. Network Security

    • Use HTTPS for all S3 communications
    • Verify SSL certificates
    • Consider using VPN for additional security
  4. System Privileges

    • Script requires administrator privileges
    • Scheduled task runs as SYSTEM (highest privilege)
    • Ensure uninstaller tool is from trusted source
  5. Logging

    • Log files may contain sensitive information
    • Secure log file locations
    • Implement log rotation and retention policies

Execution Policy

If you encounter execution policy restrictions:

# Check current policy
Get-ExecutionPolicy

# Temporarily allow script execution (for current session)
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

# Or sign the script with a code signing certificate

πŸ“‹ Requirements

System Requirements

  • Operating System: Windows 7 or later (Windows 10/11 recommended)
  • PowerShell: Version 3.0 or higher
  • .NET Framework: Version 4.5 or higher (for compression support)
  • Disk Space: At least 100 MB free in temp directory
  • Network: Internet connectivity to access S3 bucket

PowerShell Modules

No additional modules required. Script uses built-in PowerShell cmdlets:

  • Start-BitsTransfer (preferred, if available)
  • Invoke-WebRequest (fallback)
  • Expand-Archive (PowerShell 5+) or System.IO.Compression (fallback)
  • New-ScheduledTask* cmdlets

Permissions Required

  • Administrator privileges (for scheduled task creation)
  • Write access to C:\Windows\Temp\ (or custom temp path)
  • Network access to S3 bucket URL

πŸ’‘ Examples

Example 1: Basic Uninstallation

# Run with default settings (requires S3 URL to be configured in script)
.\uninstall.ps1

Example 2: Custom S3 Bucket

# Use custom S3 URL
.\uninstall.ps1 -S3Url "https://mycompany-uninstallers.s3.us-east-1.amazonaws.com/v1es/V1ESUninstallTool.zip"

Example 3: Remote Execution via WinRM

# Execute on remote computer
$session = New-PSSession -ComputerName "PC-01"
Invoke-Command -Session $session -ScriptBlock {
    Set-Location "C:\Scripts"
    .\uninstall.ps1 -S3Url "https://my-bucket.s3.region.amazonaws.com/tool.zip"
}
Remove-PSSession $session

Example 4: Batch Deployment

# Deploy to multiple computers
$computers = @("PC-01", "PC-02", "PC-03")
$s3Url = "https://my-bucket.s3.region.amazonaws.com/tool.zip"

foreach ($computer in $computers) {
    Write-Host "Processing $computer..."
    Invoke-Command -ComputerName $computer -ScriptBlock {
        param($url)
        .\uninstall.ps1 -S3Url $url
    } -ArgumentList $s3Url
}

Example 5: With Error Handling

try {
    $result = .\uninstall.ps1 -S3Url "https://my-bucket.s3.region.amazonaws.com/tool.zip"
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Success: V1ES uninstalled successfully" -ForegroundColor Green
    } else {
        Write-Host "Warning: Uninstall completed with issues. Exit code: $LASTEXITCODE" -ForegroundColor Yellow
    }
} catch {
    Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
    exit 1
}

⚠️ Error Handling

The script includes comprehensive error handling:

  • Download errors: Caught and reported with clear messages
  • Extraction errors: Validated with fallback methods
  • Task creation errors: Validated with permission checks
  • Execution errors: Monitored with timeout handling
  • All errors: Return appropriate exit codes for automation

Error Recovery

The script attempts to recover from common issues:

  • Removes existing tasks before creating new ones
  • Cleans up temporary files on failure
  • Provides detailed error messages
  • Displays relevant log files for debugging

🚧 Limitations

  1. Timeout: Maximum wait time is 150 seconds (2.5 minutes). Long-running uninstalls may timeout.
  2. Single Execution: Only one uninstallation can run at a time per system (task name conflict).
  3. Windows Only: Designed specifically for Windows operating systems.
  4. S3 Dependency: Requires internet connectivity and S3 bucket access.
  5. Administrator Required: Must run with administrator privileges.
  6. Log Display: Only shows last 80 lines of each log file.

Workarounds

  • Extended Timeout: Modify $maxWaitTime variable for longer uninstalls
  • Custom Task Name: Modify $TaskName variable for parallel executions
  • Full Logs: Manually check log files for complete output

πŸ“„ License

This script is provided as-is for use in uninstalling V1ES software. Please ensure you have proper authorization before using this script in your environment.

🀝 Contributing

Contributions are welcome! Please ensure any changes maintain backward compatibility and include appropriate error handling.

πŸ“ž Support

For issues or questions:

  1. Check the Troubleshooting section
  2. Review log files for detailed error information
  3. Verify S3 bucket configuration and permissions
  4. Ensure all prerequisites are met

πŸ“ Changelog

Version 1.0

  • Initial release
  • S3 download support
  • Scheduled task execution
  • Log file display
  • Comprehensive error handling

Note: Always test this script in a non-production environment before deploying to production systems.

About

V1ES Uninstall

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors