Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


November 15, 2004

Take Advantage of Scriptomatic 2.0 to Maximize Your WMI Scripting Efforts

It’s not just for novice scripters
RSS
Subscribe to Windows IT Pro | See More Task Automation Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

When you know which class properties are writeable, you can use Scriptomatic 2.0 to create a script, then adapt that script to modify those properties' values. For example, let's say you want to change the HcDoOnDemandCompression property's value. Follow this procedure on a computer running Windows 2003 and IIS 6.0 on a nonproduction system, lab computer, or virtual hard disk:

  1. Open Scriptomatic 2.0. Select root\MicrosoftIISv2 in the WMI Namespace box and IIsCompressionSchemesSetting in the WMI Class box to generate the script.
  2. Run the script from within Scriptomatic to determine the value of the HcDoOnDemandCompression value.
  3. Close the command-shell window.
  4. Edit the script from within Scriptomatic. Remove all the properties except for the HcDoOnDemandCompression property. You'll see all the properties listed in the For Each...Next statement that begins with the line
    For Each objItem in colitems
  5. Add the code that callout A in Listing 1 shows. The first line changes the HcDoOnDemandCompression property's value. Change the value to False if Scriptomatic displayed a True value in Step 2, or vice versa. The second line uses WMI's SWbemObject.Put_ method to write the changes to the IIS metabase. For more information about the Put_ method, see "WMI Scripting Primer: Part 2."
  6. Click Run to run the script.

After about 5 minutes, the change will be written to the IIS metabase. This example is intended only to demonstrate how you use WMI with a writeable property. For information about configuring HTTP compression, see Rem "Using WMI to Change HTTP Compression Settings."

Reading Between the Lines
A crucial aspect of creating most types of scripts is understanding the data types of the properties you're reading or writing—and creating WMI scripts is no exception. Scriptomatic 2.0 can help you gain some insight on WMI data types even though it doesn't explicitly specify the data types. To determine the data types, you need to review the Scriptomatic script and the script's output. For example, Scriptomatic displays properties with Boolean data types, String data types, and Integer data types simply by calling the name of the property in the script. The script and output for the Win32_ComputerSystem class in the root\CIMV2 namespace provide a good example of how you can deduce these three data types:

  • The script calls the objItem.BootupState property, which specifies a computer's boot-up state. In the output, the property's value is a phrase, such as Normal boot. Thus, you can deduce that this property has a String data type.
  • The script calls the objItem.InfraredSupported property, which specifies a computer's support for infrared technology. In the output, the property's value will be either True or False. Thus, you can deduce that this property has a Boolean data type.
  • The script calls the objItem.DomainRole property, which specifies the role of a computer in a domain. In the output, the property's value is a number between 0 and 5. Thus, you can deduce that this property has an Integer data type.

You can also deduce other data types by looking at the script Scriptomatic creates. For example, Scriptomatic 2.0 uses the Join function to display properties stored as arrays (Array data type) and the WMIDate-StringToDate function, which callout B in Listing 1 shows, for a property whose value is stored as a DateTime data type.

Getting a Bit More Scientific
Scriptomatic 2.0 is helpful in uncovering important details about a class and its properties, but the approach I outline in this article requires that you verify the information by using other tools, such as WBEMTest, CIM Studio, or MSDN Library documentation. Also, Scriptomatic isn't designed to uncover much about a class's methods and method parameters.

Instead of relying on other tools to help you fill the gaps, you can augment Scriptomatic's script output with the GetDataTypes function, which callout B in Listing 2 shows. This function, whose code is described in detail in "WMI Scripting Primer: Part 2," displays a class's properties and methods and their corresponding data types and parameters. In contrast to the code in "WMI Scripting Primer: Part 2," the code in Listing 2 is modified slightly to limit the display of data.

To use the GetDataTypes function in a script, follow these steps:

  1. Open Scriptomatic 2.0 and select a namespace from the WMI Namespace box and a class from the WMI Class box to generate a script.
  2. Verify that VBScript is the selected language, and make sure that you have only one computer listed in the Target Computers (comma-delimited) text box.
  3. Add the line that callout A shows. Be sure to add this code inside the outer For Each loop and replace the namespace and class name with the corresponding values that appear in the WMI Namespace and WMI Class boxes.
  4. Add the code that callout B shows. Be sure to add this code at the bottom of the script.
  5. Select the XML output format, then run Scriptomatic. When IE opens, the class's properties and their data types, as well as the class's methods and their associated parameters and data types, will be appended to the display.

Make Scriptomatic 2.0 Part of Your WMI Scripting Toolkit
The Scripting Guys chuckle when people say that Scriptomatic has its weaknesses as a development tool. The goal for Scriptomatic all along has been to serve as a learning tool to help the novice WMI scripter see the consistency inherent in WMI scripts that read class properties. Scriptomatic does a great job of providing this insight. Clearly, though, this tool has gotten a lot of attention by scripters who are well beyond the novice stage. This attention is warranted because Scriptomatic is a wonderful tool for quickly uncovering class details indirectly, as I describe in the first part of the article, and directly by augmenting the Scriptomatic code, as I demonstrate in the last part of this article.

End of Article

   Previous  1  2  [3]  Next  


Reader Comments
jdfjal;kd;fk;kd;fkdfajkdljfldajf
dklfjklajdfkljdklfjlkajfkldjf
dfkldafjdklfjljfklajflkfjaklfj
dfjklajflkdjflkajfklajfkldjfkladjfjd
kladfjlkjfkljflfjjfljdlfjjlajl

maxspeed September 23, 2007 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Task Automation Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Will Your Next Generation Server System Meet Your Infrastructure Optimization Needs?

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement