Previous Page
Next Page

Header Information

The Header information section is going to look very similar in each of the Exchange 2003 WMI scripts, so this is the only place in this chapter you will look at it. You turn on Option Explicit and On Error Resume Next, and then you name several variables, which are described in Table 20-2.

Table 20-2. Variables used in ExchangeSMTPQueue.vbs

Variable

Use

strComputer

Holds the name of the target computer

wmiNS

Holds the target namespace

wmiQuery

Holds the WMI query text

objWMIService

Holds the connection into WMI

colItems

Holds the returned data

objItem

Used to iterate through the data


Reference Information

The Reference information section of the script is used to assign values to variables that were declared in the Header information section. The variable strComputer is set to a period, which means that the query will run against the local computer. The variable wmiNS is set to the "\root\MicrosoftExchangeV2" namespace to enable you to work with Exchange 2003. In most of our scripts, the strComputer, wmiNS, and wmiQuery references will remain exactly the same. The only item needing modification in the Reference information section of the script is the class from which Select * is going to run. You set objWMIService to be equal to the object that comes back from using GetObject and the WMI moniker. This connection into WMI is targeted at strComputer and the namespace represented by wmiNS. The advantage of using variables to create the connection string is that the line of code will never need to be modified! Once you have the hook into WMI, you use that hook to cast your query. The query is contained in the wmiQuery variable, and as a result, you don't have to touch that line of code either. Here is the Reference information section:

strComputer = "."
wmiNS = "\root\MicrosoftExchangeV2"
wmiQuery = "Select * from Exchange_QueueSMTPVirtualServer"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)

Worker Information

The Worker information section of the script is a For Each...Next statement. You use the objItem variable to iterate through the data held in the colItems collection. This code does not need to be modified. This statement looks like the following:

For Each objItem In colItems

Next

Output Information

The Output information section of the script consists of a series of WScript.Echo statements. These statements are contained inside the For Each...Next statement in the Worker information section of the script. The Output information section will need to be customized for every WMI script you create using the MicrosoftExchangeV2 namespace. For ExchangeSMTPQueue.vbs, the Output information section looks like the following:

WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Description: " & objItem.Description
WScript.Echo "GlobalActionsSupported: " _
  & objItem.GlobalActionsSupported
WScript.Echo "GlobalStop: " & objItem.GlobalStop
WScript.Echo "InstallDate: " & objItem.InstallDate
WScript.Echo "Name: " & objItem.Name
WScript.Echo "ProtocolName: " & objItem.ProtocolName
WScript.Echo "Status: " & objItem.Status
WScript.Echo "VirtualMachine: " _
  & objItem.VirtualMachine
WScript.Echo "VirtualServerName: " _
  & objItem.VirtualServerName


Previous Page
Next Page