Hacking WSUS #5 of 5 -- The Holy Grail: A Remoteable "YOU PATCH NOW!" Script
So yesterday's script was great if you're sitting on the console of the server and you want that server to download, install, and reboot for patching. But, what if you want to sit in your lofty white Systems Administrator's tower and instruct your computers to do the patching for you. With remoteability to yesterday's script, you could even do your monthly patching from the comfort of your own home!
(I know this. I used to use this script to do my monthly patching from home! So, I know it works.)
To use this script, you'll need two things. First, you'll need to create a text file with a list of computer names -- one per line -- and reference that file when you run the script. You'll also need a username and password of an account that has administrator rights on the remote machines. An example: remoteYouPatchNOW.vbs computers.txt DOMAIN\Username P!. You'll also need to download the Microsoft PSTools and drop the executable for PSExec into either your path or the same folder as this script.
Lastly, you'll need to name yesterday's script "wsus-install-agent.vbs" and put it into the same folder as this script. This script will copy yesterday's script into the ADMIN$ location on the remote machine and use PSExec to remotely launch it. Perfect!
Click the link below for the code:
strComputerList = WScript.Arguments.Item(0)
strUserName = WScript.Arguments.Item(1)
strPassword = WScript.Arguments.Item(2)
strAgent = "techmentor_wsus-install-agent.vbs"
Set objShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strComputerList, 1, True)
Do While f.AtEndOfLine <> True
strComputer = f.ReadLine
fso.CopyFile strAgent, "\\" & strComputer & "\admin$\system32\", True
WScript.Echo ("psexec.exe \\" & strComputer & " -u " & strUserName & " -p " & strPassword & " " & strAgent)
Set objExecObject = objShell.Exec("psexec.exe \\" & strComputer & " -u " & strUserName & " -p " & strPassword & " cscript " & strAgent)
Loop
WScript.Echo "Done!"
So, that's our week in hacking...er, scripting WSUS! We'll revisit these scripts once I get the chance to take a look at WSUS 3.0 and see what is new and cool with its scripting exposure. If you've got any cool or interesting scripts you've built to extend WSUS, please feel free to let us know in the comments field below!