Now Available:

Featured Resources:

Newsletter

Email Address:

Subscribe





Ask the Expert

Have a question for our resident expert? .

Realtime Communities

« Microsoft to donate to charity for every Windows Live Messenger IM session created | Main | Delays, delays. More Not-Good Info on Microsoft Virtual Server Updates »

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!

TrackBack

TrackBack URL for this entry:
https://realtime-windowsserver.com/type/mt-tb.cgi/92

Most Active Posts

Recent Posts

Greg Shields' Bio:

Greg Shields is a Principal Consultant with 3t Systems in Denver, Colorado. With more than 10 years of experience in information technology, Greg has developed extensive experience in systems administration, engineering, and architecture specializing in Microsoft, Citrix, and VMware technologies. Greg is a Contributing Editor for both Redmond Magazine and Microsoft Certified Professional Magazine, authoring two regular columns along with numerous feature articles, webcasts, and white papers. He is known for his abilities to relate highly technical concepts with a drive towards fulfilling business needs. Greg is also a highly sought-after instructor and speaker, teaching system and network troubleshooting curriculum for TechMentor Events, a twice-annual IT conference, and producing computer-based training curriculum for CBT Nuggets on numerous topics. Greg is a triple Microsoft Certified Systems Engineer (MCSE) with security specialization and a Certified Citrix Enterprise Administrator (CCEA).