Skip to main content

Overview

BCU-console is designed for automation and can be integrated into various scripting environments. This guide provides practical examples for common automation scenarios.

Script Templates

Batch Scripts

Traditional Windows batch files for simple automation tasks

PowerShell

Modern PowerShell scripts with error handling and logging

Task Scheduler

Scheduled automation using Windows Task Scheduler

Enterprise Deployment

SCCM, Intune, and Group Policy integration examples

Basic Automation Patterns

Simple Unattended Uninstall

The most basic automation: uninstall applications silently without user interaction.
@echo off
echo Starting automated uninstall...

BCU-console uninstall "C:\Scripts\bloatware.bcul" /U /Q

if %ERRORLEVEL% EQU 0 (
    echo Uninstall completed successfully
) else (
    echo Uninstall failed with error code %ERRORLEVEL%
)

pause

With Logging

Capture console output for audit trails and troubleshooting.
@echo off
set LOGFILE=C:\Logs\BCU_%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.log
set LOGFILE=%LOGFILE: =0%

echo %DATE% %TIME% - Starting uninstall >> "%LOGFILE%"

BCU-console uninstall "C:\Scripts\bloatware.bcul" /U /Q /V >> "%LOGFILE%" 2>&1

if %ERRORLEVEL% EQU 0 (
    echo %DATE% %TIME% - Uninstall completed successfully >> "%LOGFILE%"
) else (
    echo %DATE% %TIME% - Uninstall failed with error %ERRORLEVEL% >> "%LOGFILE%"
)

echo Log saved to: %LOGFILE%

With Error Handling

Robust error handling for production environments.
@echo off
setlocal enabledelayedexpansion

set "BCUL_FILE=C:\Scripts\bloatware.bcul"
set "EMAIL_ON_ERROR=[email protected]"

echo Checking if uninstall list exists...
if not exist "%BCUL_FILE%" (
    echo ERROR: Uninstall list not found: %BCUL_FILE%
    exit /b 87
)

echo Starting uninstall process...
BCU-console uninstall "%BCUL_FILE%" /U /Q

set ERROR_CODE=%ERRORLEVEL%

if %ERROR_CODE% EQU 0 (
    echo SUCCESS: Uninstall completed
    exit /b 0
) else if %ERROR_CODE% EQU 1 (
    echo ERROR: Invalid arguments
    exit /b 1
) else if %ERROR_CODE% EQU 13 (
    echo ERROR: Unexpected system error
    exit /b 13
) else if %ERROR_CODE% EQU 87 (
    echo ERROR: Invalid syntax or missing file
    exit /b 87
) else if %ERROR_CODE% EQU 1223 (
    echo WARNING: Operation cancelled by user
    exit /b 1223
) else (
    echo ERROR: Unknown error code %ERROR_CODE%
    exit /b %ERROR_CODE%
)

Common Automation Scenarios

Scenario 1: Enterprise Bloatware Removal

Automatic removal of unwanted software on new workstations.
@echo off
echo ========================================
echo  Enterprise Bloatware Removal Script
echo ========================================
echo.

set "SCRIPT_DIR=%~dp0"
set "LIST_FILE=%SCRIPT_DIR%bloatware.bcul"
set "LOG_DIR=C:\IT\Logs\BCU"
set "LOG_FILE=%LOG_DIR%\Bloatware_Removal_%COMPUTERNAME%_%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%.log"

if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"

echo %DATE% %TIME% - Starting bloatware removal on %COMPUTERNAME% >> "%LOG_FILE%"
echo Computer: %COMPUTERNAME% >> "%LOG_FILE%"
echo User: %USERNAME% >> "%LOG_FILE%"
echo. >> "%LOG_FILE%"

echo Running BCU-console...
BCU-console uninstall "%LIST_FILE%" /U /Q /J=VeryGood >> "%LOG_FILE%" 2>&1

set RESULT=%ERRORLEVEL%

if %RESULT% EQU 0 (
    echo %DATE% %TIME% - SUCCESS: Bloatware removal completed >> "%LOG_FILE%"
    echo.
    echo Bloatware removed successfully!
) else (
    echo %DATE% %TIME% - ERROR: Exit code %RESULT% >> "%LOG_FILE%"
    echo.
    echo ERROR: Bloatware removal failed. Check log: %LOG_FILE%
)

echo.
echo Log file: %LOG_FILE%
echo.
pause

exit /b %RESULT%

Scenario 2: Software Inventory Collection

Regular inventory collection for compliance and asset management.
@echo off
setlocal

set "INVENTORY_DIR=\\FileServer\IT\Inventory"
set "COMPUTER_FILE=%INVENTORY_DIR%\%COMPUTERNAME%_apps.xml"

echo Collecting software inventory for %COMPUTERNAME%...

BCU-console export "%COMPUTER_FILE%" /Q

if %ERRORLEVEL% EQU 0 (
    echo Inventory exported successfully to:
    echo %COMPUTER_FILE%
) else (
    echo ERROR: Failed to export inventory
    exit /b %ERRORLEVEL%
)

Scenario 3: Pre-Deployment Cleanup

Remove old software versions before deploying new ones.
@echo off
echo ========================================
echo  Pre-Deployment Cleanup
echo ========================================
echo.

set "OLD_VERSION_LIST=C:\Deploy\old-versions.bcul"
set "NEW_INSTALLER=C:\Deploy\NewApp_v2.0.exe"

echo Step 1: Removing old versions...
BCU-console uninstall "%OLD_VERSION_LIST%" /U /Q /J=VeryGood

if %ERRORLEVEL% NEQ 0 (
    echo ERROR: Failed to remove old versions
    exit /b %ERRORLEVEL%
)

echo.
echo Step 2: Installing new version...
start /wait "" "%NEW_INSTALLER%" /S

if %ERRORLEVEL% EQU 0 (
    echo.
    echo SUCCESS: Deployment completed!
) else (
    echo.
    echo ERROR: Installation failed
    exit /b %ERRORLEVEL%
)

Scenario 4: Scheduled Maintenance

Regular cleanup of temporary software and trial versions.
PowerShell - Task Scheduler Script
<#
.SYNOPSIS
    Scheduled Maintenance Script
.DESCRIPTION
    Runs weekly to remove temporary software and trial versions
.NOTES
    Schedule with: schtasks /create /tn "BCU Maintenance" /tr "powershell.exe -File maintenance.ps1" /sc weekly /d SUN /st 02:00
#>

$ErrorActionPreference = "Stop"

# Configuration
$config = @{
    ListFile = "C:\IT\Scripts\BCU\maintenance.bcul"
    LogDir = "C:\IT\Logs\BCU\Maintenance"
    EmailOnError = $true
    EmailTo = "[email protected]"
    SmtpServer = "smtp.company.com"
}

# Setup logging
$logFile = Join-Path $config.LogDir "Maintenance_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"

if (-not (Test-Path $config.LogDir)) {
    New-Item -ItemType Directory -Path $config.LogDir -Force | Out-Null
}

Start-Transcript -Path $logFile

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "  BCU Scheduled Maintenance" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Started: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
Write-Host "Computer: $($env:COMPUTERNAME)"
Write-Host ""

try {
    # Verify list file exists
    if (-not (Test-Path $config.ListFile)) {
        throw "Maintenance list not found: $($config.ListFile)"
    }
    
    # Run uninstall
    Write-Host "Running maintenance uninstall..." -ForegroundColor Yellow
    
    $process = Start-Process -FilePath "BCU-console" `
        -ArgumentList "uninstall", $config.ListFile, "/U", "/Q", "/J" `
        -Wait -PassThru -NoNewWindow
    
    if ($process.ExitCode -eq 0) {
        Write-Host "Maintenance completed successfully" -ForegroundColor Green
        $success = $true
    } else {
        throw "Maintenance failed with exit code: $($process.ExitCode)"
    }
}
catch {
    Write-Error $_.Exception.Message
    $success = $false
    
    # Send error email if configured
    if ($config.EmailOnError) {
        $emailParams = @{
            To = $config.EmailTo
            From = "[email protected]"
            Subject = "BCU Maintenance Failed on $($env:COMPUTERNAME)"
            Body = "Maintenance task failed at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`n`nError: $($_.Exception.Message)`n`nLog: $logFile"
            SmtpServer = $config.SmtpServer
        }
        
        try {
            Send-MailMessage @emailParams
        } catch {
            Write-Error "Failed to send email: $($_.Exception.Message)"
        }
    }
}
finally {
    Write-Host ""
    Write-Host "Completed: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
    Write-Host "Log: $logFile" -ForegroundColor Cyan
    Stop-Transcript
}

exit ($success ? 0 : 1)

Windows Task Scheduler Integration

Create Scheduled Task (Command Line)

Create Task
REM Run every Sunday at 2:00 AM
schtasks /create /tn "BCU Weekly Maintenance" ^
    /tr "\"C:\IT\Scripts\BCU\maintenance.bat\"" ^
    /sc weekly /d SUN /st 02:00 ^
    /ru SYSTEM /rl HIGHEST /f

REM Run at system startup
schtasks /create /tn "BCU Bloatware Removal" ^
    /tr "\"C:\IT\Scripts\BCU\bloatware-removal.bat\"" ^
    /sc onstart /delay 0005:00 ^
    /ru SYSTEM /rl HIGHEST /f

REM Run daily inventory export
schtasks /create /tn "BCU Daily Inventory" ^
    /tr "powershell.exe -ExecutionPolicy Bypass -File C:\IT\Scripts\BCU\inventory.ps1" ^
    /sc daily /st 03:00 ^
    /ru SYSTEM /f

Create Scheduled Task (PowerShell)

PowerShell Task Creation
# Weekly maintenance task
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
    -Argument "-ExecutionPolicy Bypass -File C:\IT\Scripts\BCU\maintenance.ps1"

$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At 2am

$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest

$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries

Register-ScheduledTask -TaskName "BCU Weekly Maintenance" `
    -Action $action `
    -Trigger $trigger `
    -Principal $principal `
    -Settings $settings `
    -Description "Weekly cleanup of temporary software using BCU-console" `
    -Force

Write-Host "Scheduled task created successfully" -ForegroundColor Green

Enterprise Deployment Integration

Microsoft Endpoint Configuration Manager (SCCM)

SCCM Package Script
<#
.SYNOPSIS
    SCCM Package Script for BCU Bloatware Removal
.DESCRIPTION
    Deploy as SCCM application or package
.NOTES
    Detection Method: Check for completion marker file
#>

$ErrorActionPreference = "Stop"

# Paths
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$bcuPath = Join-Path $scriptPath "BCU-console.exe"
$listPath = Join-Path $scriptPath "bloatware.bcul"
$markerPath = "C:\ProgramData\Company\BCU\bloatware-removed.marker"
$logPath = "C:\ProgramData\Company\BCU\Logs"

# Setup logging
$logFile = Join-Path $logPath "SCCM_Deploy_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"

if (-not (Test-Path $logPath)) {
    New-Item -ItemType Directory -Path $logPath -Force | Out-Null
}

Start-Transcript -Path $logFile

try {
    Write-Host "Starting SCCM BCU deployment"
    Write-Host "Computer: $($env:COMPUTERNAME)"
    Write-Host "User: $($env:USERNAME)"
    
    # Check if already deployed
    if (Test-Path $markerPath) {
        $markerDate = (Get-Item $markerPath).LastWriteTime
        Write-Host "Already deployed on $markerDate"
        
        # Re-run if marker is older than 30 days
        if ((Get-Date).AddDays(-30) -gt $markerDate) {
            Write-Host "Marker is old, re-running deployment"
        } else {
            Write-Host "Skipping deployment"
            exit 0
        }
    }
    
    # Run BCU-console
    $process = Start-Process -FilePath $bcuPath `
        -ArgumentList "uninstall", $listPath, "/U", "/Q", "/J" `
        -Wait -PassThru -NoNewWindow
    
    if ($process.ExitCode -eq 0) {
        Write-Host "Deployment successful"
        
        # Create marker file
        $markerDir = Split-Path -Parent $markerPath
        if (-not (Test-Path $markerDir)) {
            New-Item -ItemType Directory -Path $markerDir -Force | Out-Null
        }
        
        Set-Content -Path $markerPath -Value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
        
        exit 0
    } else {
        throw "BCU-console failed with exit code: $($process.ExitCode)"
    }
}
catch {
    Write-Error $_.Exception.Message
    exit 1
}
finally {
    Stop-Transcript
}

Microsoft Intune (PowerShell Script Deployment)

Intune Deployment Script
<#
.SYNOPSIS
    Intune Win32 App Script
.DESCRIPTION
    Deploy BCU bloatware removal as Intune Win32 app
.NOTES
    Package with Microsoft Win32 Content Prep Tool
    Detection: Registry key HKLM\SOFTWARE\Company\BCU\BloatwareRemoved
#>

$ErrorActionPreference = "Stop"

# Configuration
$bcuPath = "$PSScriptRoot\BCU-console.exe"
$listPath = "$PSScriptRoot\bloatware.bcul"
$registryPath = "HKLM:\SOFTWARE\Company\BCU"
$logPath = "$env:ProgramData\Company\BCU\Logs"

# Setup logging
$logFile = Join-Path $logPath "Intune_Deploy_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"

if (-not (Test-Path $logPath)) {
    New-Item -ItemType Directory -Path $logPath -Force | Out-Null
}

Start-Transcript -Path $logFile

try {
    Write-Host "Starting Intune BCU deployment" -ForegroundColor Cyan
    Write-Host "Device: $($env:COMPUTERNAME)"
    Write-Host "User: $($env:USERNAME)"
    Write-Host ""
    
    # Verify files exist
    if (-not (Test-Path $bcuPath)) {
        throw "BCU-console.exe not found: $bcuPath"
    }
    if (-not (Test-Path $listPath)) {
        throw "Uninstall list not found: $listPath"
    }
    
    # Run BCU-console
    Write-Host "Executing BCU-console..." -ForegroundColor Yellow
    
    $process = Start-Process -FilePath $bcuPath `
        -ArgumentList "uninstall", $listPath, "/U", "/Q", "/J=VeryGood" `
        -Wait -PassThru -NoNewWindow
    
    if ($process.ExitCode -ne 0) {
        throw "BCU-console failed with exit code: $($process.ExitCode)"
    }
    
    Write-Host "BCU-console completed successfully" -ForegroundColor Green
    Write-Host ""
    
    # Create detection registry key
    Write-Host "Creating detection registry key..." -ForegroundColor Yellow
    
    if (-not (Test-Path $registryPath)) {
        New-Item -Path $registryPath -Force | Out-Null
    }
    
    Set-ItemProperty -Path $registryPath -Name "BloatwareRemoved" -Value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
    Set-ItemProperty -Path $registryPath -Name "Version" -Value "1.0"
    
    Write-Host "Deployment completed successfully" -ForegroundColor Green
    exit 0
}
catch {
    Write-Error $_.Exception.Message
    exit 1
}
finally {
    Write-Host ""
    Write-Host "Log: $logFile" -ForegroundColor Cyan
    Stop-Transcript
}

Best Practices

Never use unattended mode without thorough testing
  1. Run without /U flag first to see what will be uninstalled
  2. Test on a non-production machine
  3. Verify the uninstall list is specific enough to avoid false positives
  4. Review logs after test runs
# Test mode - prompts for confirmation
BCU-console uninstall test.bcul /Q /V

# After verification, run unattended
BCU-console uninstall test.bcul /U /Q
Always log operations for audit trails and troubleshooting
  • Redirect output to log files
  • Include timestamps in log filenames
  • Store logs in a central location
  • Implement log rotation to prevent disk space issues
# Good logging practice
$logFile = "C:\Logs\BCU_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
Start-Transcript -Path $logFile

# ... BCU operations ...

Stop-Transcript
Always verify operation success via return codes
  • Check $ERRORLEVEL (batch) or $LASTEXITCODE (PowerShell)
  • Implement appropriate error handling
  • Send alerts on failures
  • Don’t proceed with dependent operations if BCU fails
$result = Start-Process BCU-console -ArgumentList @(...) -Wait -PassThru

if ($result.ExitCode -ne 0) {
    # Handle error
    Send-Alert "BCU failed with code $($result.ExitCode)"
    exit 1
}
Start with VeryGood confidence level
  • Only use /J=VeryGood for automated tasks
  • Never use lower confidence levels in unattended mode
  • Test junk cleanup results before deploying widely
  • Monitor for false positives
# Safe for automation
BCU-console uninstall apps.bcul /U /Q /J=VeryGood

# Too risky for automation
BCU-console uninstall apps.bcul /U /Q /J=Questionable
Always validate paths before execution
  • Check if .bcul files exist before running
  • Verify BCU-console.exe is accessible
  • Ensure output directories exist for exports
  • Use absolute paths when possible
if (-not (Test-Path $bcuListFile)) {
    Write-Error "List file not found: $bcuListFile"
    exit 87
}
Run during maintenance windows
  • Schedule during off-hours (e.g., 2-4 AM)
  • Allow sufficient time for completion
  • Avoid running during backups or other maintenance
  • Consider user logon/logoff times
# Good: Sunday 2 AM
$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At 2am

# Bad: Peak business hours
# $trigger = New-ScheduledTaskTrigger -Daily -At 2pm

Common Pitfalls

Avoid These Common Mistakes
  1. Using /U without testing: Always test interactively first
  2. No error handling: Scripts should check return codes
  3. Missing logging: You’ll need logs when something goes wrong
  4. Overly broad uninstall lists: Be specific to avoid removing important software
  5. Running during business hours: Schedule during maintenance windows
  6. No network path validation: Check UNC paths before using them
  7. Ignoring junk cleanup warnings: Don’t use confidence levels below VeryGood in automation

Troubleshooting

Cause: Command syntax error or invalid junk levelSolutions:
  • Verify command syntax matches documentation
  • Check that switches are spelled correctly (/Q, /U, /V, /J)
  • Ensure junk level is valid (VeryGood, Good, Questionable, Bad, Unknown)
# Wrong
BCU-console uninstall apps.bcul /J=Medium

# Correct
BCU-console uninstall apps.bcul /J=Good
Cause: Missing file or invalid pathSolutions:
  • Verify .bcul file exists at specified path
  • Use absolute paths instead of relative paths
  • Check file permissions
  • Ensure filename is provided for export command
# Verify file before running
if (Test-Path "C:\Lists\apps.bcul") {
    BCU-console uninstall "C:\Lists\apps.bcul" /U /Q
} else {
    Write-Error "List file not found"
}
Cause: User pressed ‘N’ at confirmation promptSolutions:
  • Use /U flag to skip confirmations
  • Or ensure user understands they need to press ‘Y’
# Avoid prompts in automation
BCU-console uninstall apps.bcul /U /Q
Cause: Uninstall list doesn’t match any installed applicationsSolutions:
  • Run BCU-console list to see what’s installed
  • Verify the .bcul file was created correctly
  • Check if target applications are already uninstalled
  • Ensure .bcul file was created on same architecture (x86/x64)
# Check what's currently installed
BCU-console list /Q > current-apps.txt

Next Steps

CLI Overview

Learn about BCU-console features and use cases

Command Reference

Complete documentation of all commands and flags

Build docs developers (and LLMs) love