:: Purpose: Installs a pre-downloaded Microsoft offline update package, generated by the WSUS Offline Update tool ( http://download.wsusoffline.net/ ) :: Requirements: 1. Run this script with Administrator rights :: 2. The script expects one command-line argument when it's run (via command line/PDQ deploy/SCCM/etc) which is the patch set to apply: :: Valid patch sets: :: office_2k7-2k16 :: windows_7_and_server_2008-R2 :: windows_8.1_and_server_2012-R2 :: windows_server_2003 :: :: If the argument is missing, the installation will fail with error code 1 :: If the variables below point to non-existent sources, the installation will fail error code 2 :: :: Example: :: microsoft_offline_update_launcher.bat windows_7_and_server_2008-R2 :: :: 3. Set the repository variable to point to where the Microsoft offline update packages are. :: The final variable that gets passed to the copy operation is built like this: :: \\server\share_name\product\PATCH_DATE :: e.g. :: \\server\microsoft_offline_updates\windows_7_and_server_2008-R2\2018-01-18 :: :: Author: vocatus on reddit.com/r/sysadmin ( vocatus.gate@gmail.com ) // PGP key ID: 0x07d1490f82a211a2 :: Version: 1.7.1 / Minor comment fix :: 1.7.0 * Remove requirement to pass patch date. This was kind of pointless since we're always wanting to be on the latest patch set anyway :: / Rename REMOTE_REPOSITORY to REPOSITORY :: / Rename LOCAL_REPOSITORY to WORKING_DIRECTORY :: 1.6.2 * Fix incorrect references to %LOGFILENAME% (should be %LOGFILE%). Thanks to reddit.com/user/tastyratz :: 1.6.1 + Add cleanup of WORKING_DIRECTORY after finishing patch process :: :: 1.0 + Initial write ::::::::::::::: :: VARIABLES :: --------------- Set these to your desired values. -------------------------- :: ::::::::::::::: :: Rules for variables: :: * NO quotes! (bad: "c:\directory\path" ) :: * NO trailing slashes on the path! (bad: c:\directory\ ) :: * Spaces are okay (okay: c:\my folder\with spaces ) :: * Network paths are okay (okay: \\server\share name ) :: ( \\172.16.1.5\share name ) :: Log location and name. Do not use trailing slashes (\) :: Log max size is in bytes. If it exceeds the max then it gets rotated. 1048576 bytes is one megabyte set LOGPATH=%SystemDrive%\Logs set LOGFILE=microsoft_offline_updates.log set LOG_MAX_SIZE=2097152 :: Specify the network location where the Microsoft offline update packages are. ( Default: \\server\share\microsoft_offline_updates ) :: Specify a local directory on the target machine to store the updates in while they install. ( Default: %TEMP%\microsoft_offline_updates ) set REMOTE_REPOSITORY=\\YOUR-SERVER-NAME\repo\microsoft_offline_updates set WORKING_DIRECTORY=%TEMP%\microsoft_offline_updates :: -------------------------- Don't edit anything below this line -------------------------- :: ::::::::::::::::::::: :: Prep and checks :: ::::::::::::::::::::: @echo off set SCRIPT_VERSION=1.7.1 set SCRIPT_UPDATED=2015-09-15 :: Get the date into ISO 8601 standard date format (yyyy-mm-dd) so we can use it FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2% :: This is useful if we start from a network share; converts CWD to a drive letter pushd "%~dp0" 2>NUL cls :: These lines build the final source and destination set PRODUCT=%1 set UPDATE_PACKAGE=%REMOTE_REPOSITORY%\%PRODUCT% set WORKING_FOLDER=%WORKING_DIRECTORY%\%PRODUCT% :: Error checks. Throw error if it fails echo. if '%1%'=='' echo ERROR You didn't specify a product name. Edit this batch file with a text editor to configure it correctly. && exit /B 1 if not exist %UPDATE_PACKAGE% echo ERROR Couldn't find the update package you specified, check your path. && exit /B 2 ::::::::::::::::::::::: :: LOG FILE HANDLING :: ::::::::::::::::::::::: :: Make the logfile if it doesn't exist if not exist "%LOGPATH%" mkdir "%LOGPATH%" if not exist %LOGPATH%\%LOGFILE% echo. > %LOGPATH%\%LOGFILE% :: Check log size. If it's less than our max, then jump to the cleanup section for %%R in (%LOGPATH%\%LOGFILE%) do IF %%~zR LSS %LOG_MAX_SIZE% goto installation :: If the log was too big, go ahead and rotate it. pushd %LOGPATH% del %LOGFILE%.oldest 2>NUL rename %LOGFILE%.older %LOGFILE%.oldest 2>NUL rename %LOGFILE%.old %LOGFILE%.older 2>NUL rename %LOGFILE% %LOGFILE%.old 2>NUL popd :::::::::::::::::: :: INSTALLATION :: :::::::::::::::::: :installation :: Preclear the download area IF EXIST %WORKING_DIRECTORY% rmdir /S /Q %WORKING_DIRECTORY% :: Pull down the update package from the server and store it locally (on the target system) robocopy "%UPDATE_PACKAGE%" "%WORKING_FOLDER%" /FFT /MIR /Z /NP /LOG+:"%LOGPATH%\%LOGFILE%" :: Log file formatting echo. >> "%LOGPATH%\%LOGFILE%" :: Install the package from the local directory call "%WORKING_FOLDER%\cmd\DoUpdate.cmd" >> "%LOGPATH%\%LOGFILE%" :: Pop back to original directory. This isn't necessary in stand-alone runs of the script, but is needed when called from another script popd :: Clean up rmdir /s /q "%WORKING_DIRECTORY%" :: Return exit code to SCCM/PDQ Deploy/etc exit /B %EXIT_CODE% :eof