Thursday, 21 August 2014

CMD - force windows update for all servers in txt file


4 files needed!

start-update.bat
servers.txt
updatehf.bat
updatehf.vbs
psexec.exe

---start-update.bat-----
@echo off

rem set LISTFILE=%1
set LISTFILE=servers.txt

for /f %%a in (%LISTFILE%) do (
    echo.
    echo ---------------------------------------
    echo.
    echo %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            echo copy updatehf.vbs to %%a
                xcopy c:\temp\updatehf.vbs "\\%%a\c$\temp\" /Y /Q
            echo copy updatehf.bat to %%a
                xcopy c:\temp\updatehf.bat "\\%%a\c$\temp\" /Y | find "0 File"
                if errorlevel 1 (
                    echo open a new cmd for %%a to run updatehf.bat
                    start /min cmd /k ""C:\Windows\psexec.exe" -accepteula -s -w "c:\temp" \\%%a "c:\temp\updatehf.bat" & exit"
                    )
            )
        if errorlevel 1 (
            echo %%a unavailable
            )
    )

----eof---


---updatehf.bat---
cscript c:\temp\updatehf.vbs action:install mode:silent email:youremail@yourdomain.com restart:0
exit

---eof---



---servers.txt---
server1
server2
server3
...
---eof---

No comments:

Post a Comment