@echo off REM ==================================================================== REM ConnectWise RMM Migration Launcher REM Downloads and schedules the migration worker script REM Usage: Pass New_Tenant_Agent_URL as first parameter REM ==================================================================== SET "New_Tenant_Agent_URL=%~1" if "%New_Tenant_Agent_URL%"=="" ( echo ERROR: New_Tenant_Agent_URL parameter required echo. echo Usage: rmm-migration-launcher.bat "https://prod.setup.itsupport247.net/windows/BareboneAgent/32/TENANT_NAME/MSI/setup" exit /b 1 ) echo %New_Tenant_Agent_URL% | find "https://" >nul if %errorLevel% neq 0 ( echo ERROR: Invalid URL provided exit /b 1 ) SET TEMP_DIR=C:\Temp SET WORKER_SCRIPT=%TEMP_DIR%\rmm-migration-worker.bat SET WORKER_URL=https://scripts.pembrix.com/rmm-migration/rmm-migration-worker.bat if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%" echo Downloading migration worker script... powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('%WORKER_URL%', '%WORKER_SCRIPT%')}" 2>nul if not exist "%WORKER_SCRIPT%" ( echo ERROR: Failed to download worker script bitsadmin /transfer "WorkerDownload" /priority high "%WORKER_URL%" "%WORKER_SCRIPT%" >nul 2>&1 if not exist "%WORKER_SCRIPT%" ( echo ERROR: Could not download worker script from %WORKER_URL% exit /b 1 ) ) echo Worker script downloaded successfully echo. REM Calculate time 2 minutes from now for /f "tokens=1-3 delims=:." %%a in ("%time%") do ( set /a hour=%%a set /a minute=%%b + 2 ) if %minute% geq 60 ( set /a minute=%minute% - 60 set /a hour=%hour% + 1 ) if %hour% geq 24 set /a hour=%hour% - 24 if %hour% lss 10 set hour=0%hour% if %minute% lss 10 set minute=0%minute% set scheduletime=%hour%:%minute% echo Scheduling migration for %scheduletime%... schtasks /delete /tn "RMM_Migration" /f >nul 2>&1 schtasks /create /tn "RMM_Migration" /tr "\"%WORKER_SCRIPT%\" \"%New_Tenant_Agent_URL%\"" /sc once /st %scheduletime% /ru SYSTEM /rl HIGHEST /f >nul 2>&1 if %errorLevel% equ 0 ( echo. echo ================================================ echo Migration scheduled successfully! echo ================================================ echo Will run at: %scheduletime% echo Log: %TEMP_DIR%\RMM_Migration_[timestamp].log echo ================================================ ) else ( echo ERROR: Failed to schedule task exit /b 1 ) exit /b 0