Script Tips

Pushing the Envelope

Simple script to push out administrative executables to remote computers.

Here's a quick trick where you can use Windows Script Host 5.6 to push out scripts to a remote computer and have them execute locally on that computer. It's a useful administrative trick!

Say you have a script named C:\Script.vbs on your computer, and you want that computer to be copied to a computer named ClientB and executed. Nothing could be simpler! Just use this code:

Dim oController, oRemote
Set oController = WScript.CreateObject("WSHController")
Set oRemote = oController.CreateScript("c:\Script.vbs", _
   "ClientB")
oRemote.Execute

The oRemote has a Status property that tells you what's going on; to be notified when the remote script has finished, just add this code:

Do While oRemote.Status = 0
   WScript.Sleep 1000
Loop
WScript.Echo "Remote script finished!"

It's that easy. Now you can push out scripts to execute in a distributed fashion (sounds fancy, doesn't it?) and even keep track of when they're finished. It's all built into WSH 5.6 and it only takes a few lines of code to operate!

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is Curriculum Director for IT Pro Content for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus
Most   Popular

Upcoming Training Events