
The first challenge can be seen by looking at the column names returned by the schtasks command.
Even the basic schtasks command (no options) has a column name of Next Run Time. Since this column
name includes spaces, it cannot be used as-is as an attribute name in an XML document. Other column
names returned by the more verbose execution of schtasks have similar problems. To preserve these
column names in the form that they are returned from the schtasks command, but still allow for XML
handling, the names are encoded with the ToCMBase64String function:
function ToCMBase64String([string]$input_string)
{
return [string]("cmbase64-" +
[Sys-
tem.Co-
nvert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($input_
string))).replace("=","-")
}
This function uses Unicode base64 encoding, along with some character substitution (a dash instead of an
equal sign) to create an XML-legal form of any element or attribute name. The string is prefixed with
cmbase64- to indicate to the VCM inserter that the data will need to be decoded prior to loading it into
the VCM database. The end result is that rather than containing invalid data like this:
<Next Run Time>
12:32:00, 5/26/2010
</Next Run Time>
The XML will contain this:
<cmbase64-TgBlAHgAdAAgAFIAdQBuACAAVABpAG0AZQA->
12:32:00, 5/26/2010
</cmbase64-TgBlAHgAdAAgAFIAdQBuACAAVABpAG0AZQA->
The second problem is that the <schtasks> command does not include any unique and repeatable
identifier for specific task entries. For example, many test systems observed had more than one task with
the name: GoogleUpdateTaskMachineCore. Unique element names are a requirement for valid VCM
XML, and repeatable identifiers are desirable to prevent false indications of changes at the VCM Collector.
For example, if the script was to arbitrarily label rows as Task1, Task2, …, and Task1 was deleted, Task2
would then become Task1, and VCM would show a lot of changed details for Task1 (command line
changed, next run time changed, etc), when in fact, that task had not changed at all – it had only changed
places in the sequence.
One way to handle creation of unique and repeatable names for elements is to create a name based on a
hash of the data contained in the row. That is useful for data that has no name-type attribute at all. In this
case, however, there is a task name, but it is not guaranteed to be unique. Since the task name is user-
friendly and useful, it is desirable to try to preserve and use it through the collection script. To preserve it,
the task name is used as the element name for task rows, but the “increment” option is selected for
duplicate handling when creating a collection filter based on this script. This action allows the collection
process to add an incremental entry to a list of multiple entries with the same task name: the first example
of GoogleUpdateTaskMachineCore, while the second example will be relabeled as
GoogleUpdateTaskMachineCore_1.
Getting Started with VCM
VMware, Inc. 79
Commenti su questo manuale