VMware VCENTER CONFIGURATION MANAGER 5.3 Getting Started Manual page 78

Vcenter configuration manager installation and getting started guide
Hide thumbs Also See for VCENTER CONFIGURATION MANAGER 5.3:
Table of Contents

Advertisement

vCenter Configuration Manager Installation and Getting Started Guide
Example of Developing a Custom PowerShell Script for Use with the WCI Data Type
In this example, the objective is to collect scheduled tasks information from Windows clients. On newer
systems, Windows conveniently provides the schtasks.exe utility to report on scheduled tasks created
either through the Task Scheduler user interface or through use of the AT command.
Running schtasks by itself returns only basic data about tasks.
n
Adding the /query /v switches provides additional information, but the formatting is difficult for
n
automated processing.
The schtasks /query /? command provides additional possibilities.
n
The option set of schtasks /query /v /fo:csv is selected as the source for the data for the
n
collection script. These options give full details for all tasks in a comma-separated value result set.
PowerShell makes working with tabular result sets from commands easy. A first step for this script is to
run a command similar to:
$schtasks = schtasks /query /v /fo:csv
Since the data returned from schtasks includes multiple rows, PowerShell makes the $schtasks
variable into an array. As such, $schtasks[0] represents the first row returned from the command.
Viewing the result set by looking at $schtasks[n] shows that that the first line, $schtasks[0], is blank;
$schtasks[1] contains column names, and $schtasks[2] is the first row of task data. The goal, then, is
to parse this data into a structure compatible with VCM's XML format for return to the Collector.
The Scheduled Tasks script uses the split method of PowerShell strings to separate the columns of the
$schtasks rows into separate values in arrays. The column names row provides the names to use for
attributes, and the corresponding data from the scheduled task rows provide the values to use for these
attributes.
Once parsed, the XML returned by the script should look something like:
<schtasks>
</schtasks>
The <schtasks> top-level name is an arbitrary name picked to distinguish the results of this script from
others. A couple of additional challenges must also be overcome with this data, related to column names
returned by the schtasks command, and the fact that the schtasks command does not include any
unique and repeatable identifier for specific task entries. Details about these challenges are described next.
78
<taskname1>
<attribute1>Value1</attribute1>
<attribute2>Value2</attribute2>
...
</taskname1>
<taskname2>
<attribute1>Value1</attribute1>
<attribute2>Value2</attribute2>
...
</taskname2>
...
VMware, Inc.

Advertisement

Table of Contents
loading

Table of Contents