After you download Scriptomatic, run scriptomatic.hta to open the tool. The primary screen contains a drop-down list of WMI classes for you to select from. When you select a class, the tool automatically returns a script that will report every item of that class on the local system. (The scripts always point to the local PC, but you can modify the scripts to run on other PCs in your organization.) For example, when you select Win32_OperatingSystem from the list, the tool instantly creates a script that reports every item within the Win32_OperatingSystem class. If you then click Run, Scriptomatic uses cscript.exe to execute the script, opening a command window and placing the results into that command window. You can modify the created script to export the results into Excel.
Listing 2 shows the Scriptomatic-generated Win32_OperatingSystem class script, which I've modified in several ways. First, for the sake of brevity, I've shortened the script so that it extracts only the CSName, Caption, and Version properties. (On an XP system, CSName is the client's short name, Caption is some text along the lines of Microsoft Windows XP Professional, and Version is the OS build version numberfor example, 5.1.2600.) I've also added code that creates an Excel Application object, adds a workbook to that object, and names the first worksheet OS Data. The code then places column headings (i.e., PC Name, Caption, and Version) in the first three cells in Row 1 (i.e., A1, B1, and C1). To make the headings stand out, the code sets those cells' background color to dark blue and sets the text to a bold white font. (To discover how I determined the code to use to automate these Excel tasks, see the sidebar "Formatting the Reports," page 4.)
The next three lines of code are straight from the Scriptomatic script and extract data from the Win32_OperatingSystem class into a collection called colItems. Then, to populate the spreadsheet, the code sets a row index marker (which starts at Row 2, after my heading row) and enters a loop through the collection. This loop adds data into the three columns, using the row index to target the correct cell each time. At the end of the loop, the code increments the row index marker. (Using a For Each...Next loop through colItems when only one item exists in the collection might seem silly, but this script is simply a generic example of how to import your data into Excel. The advantage of the Scriptomatic scripts is that they print every item for every returned result. Depending on the WMI class you select, those items can become quite numerous. You can modify the sample script in Listing 2 as necessary to start each new item on a new row.)
After all the data is in the spreadsheet, the code selects all the cells in the worksheet and autofits the width of the columns and the rows to make the report easier to read. Last, the code makes the Excel spreadsheet visible. I could have written the script to make the spreadsheet visible earlier so that I could watch the script populate the spreadsheet, but doing so introduces the risk of the user accidentally clicking the spreadsheet while the script is workingan action that would interrupt the script and cause it to abort with an error. If you never intend to show a system's user the data you're retrieving from that system, you can simply leave out the code that makes Excel visible and let the entire process run in the background.
If you want to save the Excel spreadsheet, then close Excel, simply add several lines to the end of the script. For example, to save the spreadsheet to the local system under the filename report.xls, use the following code:
appExcel.ActiveWorkbook.SaveAs _
"C:\report.xls"
appExcel.Workbooks.Close
appExcel.Quit
To open a saved file in another script and have this second script perform additional changes, save the file, and close it, use the following code:
appExcel.Workbooks.Open _
"C:\report.xls"
' Perform your changes
appExcel.ActiveWorkbook.Save
appExcel.Workbooks.Close
appExcel.Quit
Remote PCs
Prev. page
1
[2]
3
4
next page