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.
This script automates the uninstallation process of V1ES software by:
- Downloading the V1ES uninstaller tool from an S3 bucket
- Extracting the tool to a temporary directory
- Creating a Windows Scheduled Task to run the uninstaller with SYSTEM privileges
- Monitoring the uninstallation process
- Displaying relevant log files
- Returning appropriate exit codes
The script is designed to run non-interactively and can be executed remotely or via deployment tools.
- 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
- 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)
-
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)
-
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
-
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
https://[bucket-name].s3.[region].amazonaws.com/[path]/[filename].zip
Example:
https://my-uninstaller-bucket.s3.us-east-1.amazonaws.com/tools/V1ESUninstallTool.zip
- 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
.\uninstall.ps1.\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/path/to/tool.zip".\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/tool.zip" -V1ESUninstPath "D:\Temp\V1ESUninstall\"# Right-click PowerShell and select "Run as Administrator"
.\uninstall.ps1Invoke-Command -ComputerName "RemotePC" -ScriptBlock {
Set-Location "C:\Scripts"
.\uninstall.ps1 -S3Url "https://your-bucket.s3.region.amazonaws.com/tool.zip"
}| 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 |
# 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"-
TLS Configuration
- Enables TLS 1.2 for secure S3 communication
-
Download Phase
- Downloads the uninstaller ZIP from S3
- Uses BITS (preferred) or Invoke-WebRequest (fallback)
- Validates download completion
-
Extraction Phase
- Extracts ZIP to temporary directory
- Supports both PowerShell 5+ and older versions
- Locates the executable (
V1ESUninstallTool.exeor first.exefound)
-
Task Creation
- Removes any existing task with the same name
- Creates a scheduled task with SYSTEM privileges
- Configures task to run silently (
/qnargument)
-
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
-
Logging Phase
- Displays relevant log files (last 80 lines each)
- Checks multiple log file locations
-
Cleanup Phase
- Removes the scheduled task
- Returns appropriate exit code
- 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
| 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 |
# Check exit code
.\uninstall.ps1
if ($LASTEXITCODE -eq 0) {
Write-Host "Uninstall successful"
} else {
Write-Host "Uninstall failed with code: $LASTEXITCODE"
}The script automatically displays the last 80 lines of the following log files (if they exist):
C:\Windows\Temp\V1ESUninst\V1ESUninstallTool.logC:\Windows\Temp\V1ESUninst\ComUnist.logC:\Windows\Temp\V1ESUninst\Log_CUT.logC:\Windows\Temp\V1ESUninst\DSA_CUT.logC:\Windows\Temp\XBCUninstaller.log
# 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
}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 HeadError: 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"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\" -RecurseWarning: 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
$maxWaitTimeif needed (currently 150 seconds)
# Check task status manually
Get-ScheduledTask -TaskName "V1ES Uninstall Task" -ErrorAction SilentlyContinue
Get-ScheduledTaskInfo -TaskName "V1ES Uninstall Task" -ErrorAction SilentlyContinueError: 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\"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"-
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
-
Script Execution
- Verify script integrity before execution
- Use code signing for production deployments
- Restrict script execution via Group Policy if needed
-
Network Security
- Use HTTPS for all S3 communications
- Verify SSL certificates
- Consider using VPN for additional security
-
System Privileges
- Script requires administrator privileges
- Scheduled task runs as SYSTEM (highest privilege)
- Ensure uninstaller tool is from trusted source
-
Logging
- Log files may contain sensitive information
- Secure log file locations
- Implement log rotation and retention policies
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- 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
No additional modules required. Script uses built-in PowerShell cmdlets:
Start-BitsTransfer(preferred, if available)Invoke-WebRequest(fallback)Expand-Archive(PowerShell 5+) orSystem.IO.Compression(fallback)New-ScheduledTask*cmdlets
- Administrator privileges (for scheduled task creation)
- Write access to
C:\Windows\Temp\(or custom temp path) - Network access to S3 bucket URL
# Run with default settings (requires S3 URL to be configured in script)
.\uninstall.ps1# Use custom S3 URL
.\uninstall.ps1 -S3Url "https://mycompany-uninstallers.s3.us-east-1.amazonaws.com/v1es/V1ESUninstallTool.zip"# 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# 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
}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
}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
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
- Timeout: Maximum wait time is 150 seconds (2.5 minutes). Long-running uninstalls may timeout.
- Single Execution: Only one uninstallation can run at a time per system (task name conflict).
- Windows Only: Designed specifically for Windows operating systems.
- S3 Dependency: Requires internet connectivity and S3 bucket access.
- Administrator Required: Must run with administrator privileges.
- Log Display: Only shows last 80 lines of each log file.
- Extended Timeout: Modify
$maxWaitTimevariable for longer uninstalls - Custom Task Name: Modify
$TaskNamevariable for parallel executions - Full Logs: Manually check log files for complete output
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.
Contributions are welcome! Please ensure any changes maintain backward compatibility and include appropriate error handling.
For issues or questions:
- Check the Troubleshooting section
- Review log files for detailed error information
- Verify S3 bucket configuration and permissions
- Ensure all prerequisites are met
- 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.