Post-Setup batch script partially runs

carlosmp

New Member
Messages
9
Reaction score
1
I seem to have an issue with my post-setup script. It seems to run up to the point of installing chocolatey. after that it stops. If i run the command manually (which is why i have the rmdir for chocolatey). It runs perfectly fine with no user intervention. Any ideas? Should i just put all of this in a single batch file and call it from the post setup? I can do it in powershell and generate myself logs, etc. so i know what's going on...

Code:
echo ===== Starting RMM Customizations
echo ===== Installing Control
msiexec /i "C:\ProgramData\RMM\ClientSetup.msi" /qn
echo ===== Configuring Power Schemes
powercfg -restoredefaultschemes
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61
powercfg -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
powercfg /Change standby-timeout-ac 0
echo ===== Importing wireless profile
netsh wlan add profile filename="C:\ProgramData\RMM\bench.xml"
echo ===== Installing RMM Tools
msiexec /i "C:\ProgramData\RMM\SyncroSetup.msi" /qn
echo ===== Setting account Options
net accounts /maxpwage:unlimited
echo ===== Installing Chocolatey Modules
rmdir /s /q %ALLUSERSPROFILE%\chocolatey
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
echo ===== Installing base Apps
choco install -y notepadplusplus adobereader googlechrome 7zip.install logioptionsplus
echo ===== Installing Office (Will take some time)
choco install -y --force office365business --params "'/configpath:C:\ProgramData\RMM\Office-Install-BP.xml'"
echo ===== Detecing Manufacturer for Update Utilities
for /f "tokens=2 delims==" %%a in ('wmic computersystem get manufacturer /format:list') do set manufacturer=%%a
set manufacturer=%manufacturer: =%
setlocal enabledelayedexpansion
set "first4=!manufacturer:~0,4!"
endlocal
for %%A in ("!first4!") do set "first4=%%~A"
set first4=%first4:~0,4%
set first4=%first4: =%
if /i "%first4%"=="leno" (
    choco install -y lenovo-thinkvantage-system-update
) else if /i "%first4%"=="dell" (
     choco install -y dellcommandupdate
)
 
I wouldn't join (on the same line) the PS install command and the set PATH.
Code:
powershell -NoProfile -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
set PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install adobereader -y

&& is defined as "only run the next command if the first command succeeds". The problem is if your PS command to install Chocolatey fails, you're not checking ERRORLEVEL and to skip all of the choco install's. So it doesn't matter anyway if they're not on the same line.

If you want to log any script errors, run it from Post-Setup as:

CommandParameters
cmd/c \path\to\myscript.bat 2>&1 > C:\path\log.txt
 
Thanks - I had it that way and was getting the same result, so decided to try the original way as suggested from Chocolatey. once the machine finishes the "setup" when i login, the chocolatey directory is there, but empty. Almost as if it didn't download. I wonder if i hsould insert a pause to make sure there's internet access. Most of the time the machiens are hardwired, so unless it's a very new machine/driver needed, they always connect, as within a few minutes of the process starting i see the machine report to our ScreenConnect server. I may try to use a power shell script to run everything else, since i can do a bit more logging, etc.
 
try this code (is better structured and optimized and has logging )

Code:
@echo off
setlocal enabledelayedexpansion

REM --- Configuration ---
set RMM_BASE_PATH=C:\ProgramData\RMM
set WIRELESS_PROFILE=%RMM_BASE_PATH%\bench.xml
set OFFICE_CONFIG=%RMM_BASE_PATH%\Office-Install-BP.xml
set LOGFILE=C:\RMM_Setup.log

REM --- Helper function for Chocolatey installation ---
:InstallChocoPackage
echo ===== Installing %~1 ===== >> "%LOGFILE%"
choco install -y %~1 >> "%LOGFILE%" 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Error installing %~1. >> "%LOGFILE%"
    exit /b 1
)
goto :eof

REM --- Start of customizations ---
echo ===== Starting RMM Customizations ===== >> "%LOGFILE%"

REM --- Install RMM Client ---
echo ===== Installing Control ===== >> "%LOGFILE%"
msiexec /i "%RMM_BASE_PATH%\ClientSetup.msi" /qn >> "%LOGFILE%" 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Error installing ClientSetup.msi. >> "%LOGFILE%"
    exit /b 1
)

REM --- Configure Power Schemes ---
echo ===== Configuring Power Schemes ===== >> "%LOGFILE%"
powercfg -restoredefaultschemes >> "%LOGFILE%" 2>&1
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61 >> "%LOGFILE%" 2>&1
powercfg -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c >> "%LOGFILE%" 2>&1
powercfg /Change standby-timeout-ac 0 >> "%LOGFILE%" 2>&1

REM --- Import Wireless Profile ---
echo ===== Importing wireless profile ===== >> "%LOGFILE%"
netsh wlan add profile filename="%WIRELESS_PROFILE%" >> "%LOGFILE%" 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Error importing wireless profile. >> "%LOGFILE%"
    exit /b 1
)

REM --- Install RMM Tools ---
echo ===== Installing RMM Tools ===== >> "%LOGFILE%"
msiexec /i "%RMM_BASE_PATH%\SyncroSetup.msi" /qn >> "%LOGFILE%" 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Error installing SyncroSetup.msi. >> "%LOGFILE%"
    exit /b 1
)

REM --- Account Settings ---
echo ===== Setting account Options ===== >> "%LOGFILE%"
net accounts /maxpwage:unlimited >> "%LOGFILE%" 2>&1

REM --- Install/Update Chocolatey ---
echo ===== Installing Chocolatey Modules ===== >> "%LOGFILE%"
IF EXIST "%ALLUSERSPROFILE%\chocolatey" (
  echo Chocolatey is already installed.  Updating... >> "%LOGFILE%"
  choco upgrade chocolatey -y >> "%LOGFILE%" 2>&1
   if %ERRORLEVEL% NEQ 0 (
    echo Error updating Chocolatey. >> "%LOGFILE%"
    exit /b 1
)
) ELSE (
    echo Installing Chocolatey... >> "%LOGFILE%"
    powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" >> "%LOGFILE%" 2>&1
    if %ERRORLEVEL% NEQ 0 (
        echo Error installing Chocolatey. >> "%LOGFILE%"
        exit /b 1
    )
    SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)



REM --- Install Base Applications ---
echo ===== Installing base Apps ===== >> "%LOGFILE%"
call :InstallChocoPackage notepadplusplus
call :InstallChocoPackage adobereader
call :InstallChocoPackage googlechrome
call :InstallChocoPackage 7zip.install
call :InstallChocoPackage logioptionsplus

REM --- Install Office ---
echo ===== Installing Office (Will take some time) ===== >> "%LOGFILE%"
call :InstallChocoPackage office365business --params "'/configpath:%OFFICE_CONFIG%'"

REM --- Detect Manufacturer and Install Update Utilities ---
echo ===== Detecting Manufacturer for Update Utilities ===== >> "%LOGFILE%"
wmic computersystem get manufacturer /format:list | findstr /i "lenovo" > nul
if %ERRORLEVEL% EQU 0 (
    call :InstallChocoPackage lenovo-thinkvantage-system-update
)

wmic computersystem get manufacturer /format:list | findstr /i "dell" > nul
if %ERRORLEVEL% EQU 0 (
    call :InstallChocoPackage dellcommandupdate
)

echo ===== RMM Customizations Completed ===== >> "%LOGFILE%"
endlocal
 
Back
Top