Now Available:

Featured Resource:

line

Newsletter

Email Address:


line

Ask the Expert

Have a question for our resident expert? Email your questions to Greg.

« 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@ssW0rd!. 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:
http://www.realtime-windowsserver.com/type/mt-tb.cgi/92

Post a comment

(All comments are approved by site leader before appearing here. Thanks for commenting!)

line

Greg Shields' Bio:

Greg Shields, is an independent author, instructor, and IT consultant based in Denver, Colorado, and a co-founder of Concentrated Technology. With nearly 15 years of experience in information technology, Greg has developed extensive experience in systems administration, engineering, and architecture specializing in Microsoft systems management, remote application, and virtualization technologies. Greg is a Contributing Editor for Redmond Magazine, MCPmag.com, and Virtualization Review Magazine and is the author of five books, including Windows Server 2008:  What’s New / What’s Changed. Greg is also a highly sought-after instructor and speaker, speaking regularly at conferences like TechMentor Events, and producing computer-based training curriculum for CBT Nuggets.  Greg is a recipient of Microsoft "Most Valuable Professional" award with a specialization in Windows Terminal Services.