This article provides instructions for creating a batch script to update a configuration file with a new IP address, deploying it via Group Policy Object (GPO), and ensuring successful execution on target machines.
.bat
file (e.g., update_ip.bat
)@echo offREM Define the file path and new IP address set "filePath=C:\Program Files\Vembu\VembuIntegrationService\conf\ephost.conf" set "newIP=192.168.1.100" REM Generate a timestamp in the format DayMMDD_YYYY_HHMMSS for /f "tokens=1-4 delims=/-:., " %%a in ('echo %date% %time%') do ( REM Get the day abbreviation for /f "tokens=1 delims= " %%x in ('echo %date%') do set "dayAbbreviation=%%x" REM Extract the month, day, year, and time components set "monthDay=%%b%%c" set "year=%%a" set "timePart=%%d" ) REM Extract seconds from %time% for /f "tokens=1-2 delims=:" %%a in ("%time%") do set "seconds=%%b" REM Combine components to create the timestamp set "timestamp=%dayAbbreviation%%monthDay%_%year%_%timePart%%seconds%" REM Create a backup file name with the timestamp set "backupFile=%filePath%.%timestamp%.bak" REM Check if the original file exists if not exist "%filePath%" ( echo File not found: "%filePath%" pause exit /b 1 ) REM Create a backup of the original file copy "%filePath%" "%backupFile%" >nul if errorlevel 1 ( echo Failed to create a backup of the file. pause exit /b 1 ) echo Backup of the original file created: "%backupFile%" REM Replace the content of the file with the new IP ( echo %newIP% ) > "%filePath%" if errorlevel 1 ( echo Failed to update the file with the new IP address. pause exit /b 1 ) REM Success message echo Successfully replaced the IP in %filePath% with %newIP%. pause
filePath
: Path to the configuration file to be updated (e.g., C:\Program Files\Vembu\VembuIntegrationService\conf\ephost.conf
).newIP
: The new IP address to replace the existing content (e.g., 192.168.1.100
).For computers:
Computer Configuration → Policies → Windows Settings → Scripts (Startup/Shutdown) → Startup.For users:
User Configuration → Policies → Windows Settings → Scripts (Logon/Logoff) → Logon.
gpupdate /force
By following these steps, you can efficiently deploy the batch script to update configuration files across multiple machines using GPO. This approach ensures a seamless update process while maintaining a backup of the original configuration.