Automate Tasks with Scriptomatic
Hard-working programmers solve problems, but good programmers solve their problems once by writing tools to automate repetitive tasks.
February 2, 2005
When I was in college, I had the good fortune to take several computer science classes from one of Georgia Tech's legends, a man named gus Baird (his real name was Augustus, and he insisted that the g in gus be lower case). gus was a terrific instructor. Among the basic principles he taught was a simple one: Hard-working programmers solve problems, but good programmers solve their problems once by writing tools to automate repetitive tasks. The release of the new version of Scriptomatic from the Microsoft Scripting Guys (see http://www.microsoft.com/technet/scriptcenter ) reminded me of gus's maxim. Scriptomatic automates the process of writing several different kinds of WMI scripts, which has two benefits. For new scripters, it drastically lowers the difficulty of using WMI; for experienced scripters, it provides a simple way to crank out new scripts from a known set of basic scripts.
After you download the Scriptomatic 2.0 from http://www.microsoft.com/downloads/details.aspx?familyid=09dfc342-648b-4119-b7eb-783b0f7d1178&displaylang=en and install it, you'll find that you've suddenly gained the ability to create about multiple types of scripts. The original Scriptomatic could produce only VBScript code, but the new version can write scripts in the popular Perl and Python scripting languages, as well as in JavaScript. Better yet, you can easily target a single script at multiple computers, giving you an easy way to write one script that automatically gathers data from all your Exchange servers. Best of all, you can choose the output format for the script's data. The default dumps data on the command line, but you can also output plain text, HTML, Microsoft Office Excel, or XML format data to a file.
How easy is Scriptomatic to use? Check out the script I created (see below), which displays all the properties of the DSAccess objects exposed by Windows Management Instrumentation (WMI) on my two Exchange servers. Here's how I did it:
1. I launched Scriptomatic from BATMAN.
2. I clicked on the WMI Namespace pull-down menu and selected rootMicrosoftExchangeV2. (The list of namespaces and classes are dynamically generated according to the providers installed on the machine on which you're running Scriptomatic.)
3. From the WMI Class pull-down menu, I selected Exchange_DSAccessDC.
4. In the Target Computers field, I entered SUPERMAN as a computer name.
5. I clicked Update Script, then Run. Total: six clicks and eight keystrokes.
The script itself is easy to read. Admittedly, it doesn't do anything except echo the properties of the selected object, but if you don't already know the names and types of the properties in a particular class, using the script is an easy way to find out. With a little tweaking, you could easily turn this script into a tool that could report back on the current DSAccess configuration for all the servers in an domain, Exchange organization, or organizational unit (OU).
We won't see the scripting improvements promised for Exchange 12 for a while yet. In the meantime, you'll probably be surprised at how much data you can gather (and how many settings and behaviors you can change) using WMI. Scriptomatic and the related resources at the Scripting Center are a great way to get started with Exchange scripting.
On Error Resume Next
Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20
arrComputers = Array("BATMAN","superman") For Each strComputer In arrComputers
WScript.Echo WScript.Echo "=====================================
"
WScript.Echo "Computer: " & strComputer WScript.Echo "
====================================="
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootMicrosoftExchangeV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Exchange_DSAccessDC", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "ConfigurationType: " & objItem.ConfigurationType
WScript.Echo "Description: " & objItem.Description
WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "IsFast: " & objItem.IsFast
WScript.Echo "IsInSync: " & objItem.IsInSync WScript.Echo "IsUp: " & objItem.IsUp
WScript.Echo "LDAPPort: " & objItem.LDAPPort
WScript.Echo "Name: " & objItem.Name WScript.Echo "Status: " & objItem.Status
WScript.Echo "Type: " & objItem.Type
WScript.Echo
Next
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm: WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) __
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function
About the Author
You May Also Like