Script Generator

In this article: Script Options  |  General Script Format  |  Reporting Class Information
Reporting Class Association Information
 |  Setting Class Property Values  |  Executing a Class Method
Executing WMI Queries
 |  Generating a Script for a Pre-configured Report

WMIX includes a Script Engine which can be triggered at any point while you use the WMIX interface. The Script Generator creates complete WMI Scripts that can be executed at the command prompt. You can also select to use only parts of the generated script in your own scripts.

 

The Script Generator can be called from any of the WMIX Views: Browser View, Namespace & Class View and WMI Query View. It is accessible either via the context sensitive menu of an object, via the Information Panel or by clicking on the Generate Script button located in the Ribbon bar.

Using the Script Generator, you will be able to:

Script Options

The Script Generator currently has only one option which controls whether or not you are prompted for a file name & path each time you generate a script. This option can be configured in the General Settings tab of WMIX Options.

General Script Format

No matter what type of script you decide to create, the general format of the script is always the same. It is composed of a Main Loop which calls one or more script function for each target computer. The selected script actions are placed into script functions which are in turn called by the Main Loop. This format makes it easy for the functions to be copied from the generated script and pasted into your own script.

' * * * * * * * * * *  START OF MAIN LOOP >>
For Each
strComputer In arrComputers    
execute_WMIfunction1(strComputer)
execute_WMIfunction2(strComputer)

Next

' << END OF MAIN LOOP * * * * * * * * * *

Function execute_WMIfunction1()
...

End Function

Function execute_WMIfunction2()
...

End Function

The list of target machines is defined by the command line parameters:

Reporting Class Information

WMIX can be used to generate scripts which queries the instances of a WMI class or the properties of a single instance of a WMI class.

WMIX automatically creates all script support functions to:

To generate a Class Information Report Script

  1. Select a class object from the Browser View or the Namespace & Class View

  2. Right click on the mouse and select Script: Query Class Instances
    or


    click on the Script: Query Class Instance link in the Information Panel

    or

    click on the
    button in the Ribbon bar.

Depending on your selection, a WMI Class Definition Object or a WMI Class Instance Object, you will be presented with different scripting choices.

 

 

Reporting Class Association Information

WMIX can also be used to query the associated instances of a WMI Class with another WMI Class. To do so, browse through the associations of an object in the Browser View (see: Displaying Object Associations), select a resulting class instance or its parent class, and then generate a script to Query Class Instances.

For example, to browse through the associations of a Share instance to disclose the Directory association, expand the share directory instance to disclose the Directory Contains File association and query its instances. You should end up with a structure similar to this one:

Then right-click on the All File (CIM) class object and select Script: Query Class Instances.

If the All File (CIM) class would have been a root object, then the resulting script would query information from all files on the system. However, since this class is the result of an association with the C:\ directory, the resulting script only queries the instances of the files within that directory. The following code is generated:

Set wbemObjectSet = wbemServices.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='c:\'} WHERE AssocClass=CIM_DirectoryContainsFile ResultClass=CIM_DataFile")

Setting Class Property Values

WMIX can generate script to set the value of writable properties of a class. To do so, open the properties window of a class instance (see: View Class Instance Properties), modify the writable properties to the desired values and click on the Export as a Script button.

Executing a Class Method

WMIX can be used to generate scripts which execute a method of a WMI class. To do so, open the WMIX Execute Method dialog (see: Executing Management Tasks), enter the method parameter values if applicable, then click on the Export as a Script button.

Executing WMI Queries

To generate a script which executes a specific WMI Query, select the Query WMI View, enter the WMI Query to execute, and then click on the button in the Ribbon bar.

Generating a Script for a Pre-configured Report

WMIX can create a WMI script which queries the information as configured in a pre-configured report template (see: Report Manager).

To do so:

  1. Click on the Report Wizard button in the ribbon bar.

  2. Click on Next in the WMIX Report Wizard and select the report template to use for the script.

  3. Click on the Script button

You can also click on the Report Selection Extended menu and select Export Report as a Script.