Previous Page
Next Page

One Step Further: Using the Exchange_Mailbox Class

In this section, you create a script that connects to the MicrosoftExchangeV2 namespace and queries the Exchange_Mailbox class.

1.
Open \My Documents\Microsoft Press\VBScriptSBS\Templates\BlankTemplate.vbs in Notepad or some other script editor and save it as YourNameExchangeMailbox.vbs.

2.
As the first non-commented line in the new file, type Option Explicit.

3.
You need to declare six variables: strComputer, wmiNS, wmiQuery, objWMIService, colItems, and objItem. In addition, add On Error Resume Next, but comment out the line during development. The completed Header information section of your script will look like the following:

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem

4.
Use the variable strComputer to hold the string ".". This line of code will look like the following:

strComputer = "."

5.
Use the variable wmiNS to hold the string "\root\MicrosoftExchangeV2". This line of code looks like the following:

wmiNS = "\root\MicrosoftExchangeV2"

6.
Use the wmiQuery variable to hold the string "Select * from Exchange_Mailbox". This line of code looks like the following:

wmiQuery = "Select * from Exchange_Mailbox"

7.
Set the variable objWMIService to be equal to the object that comes back from using the GetObject command into WMI. Use the winmgmts moniker, specify strComputer as the target computer, and specify wmiNS as the target namespace. This line of code looks like the following:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)

8.
Set the colItems variable to hold the data that comes back from running the query contained in the variable wmiQuery when you use the ExecQuery method. This line of code looks like the following:

Set colItems = objWMIService.ExecQuery(wmiQuery)

9.
Create an empty For Each...Next statement. Use objItem as your placeholder and use colItems as the collection to be iterated through. This will look like the following:

For Each objItem In colItems

Next

10.
Open the \My Documents\Microsoft Press\VBScriptSBS\ch20\OneStepFurther\StarterFileForExchangeMailBox.txtfile file. This file contains the series of WScript.Echo commands that goes inside the empty For Each...Next statement that was created in step 9.

11.
Copy all the WScript.Echo commands contained in \My Documents\Microsoft Press\VBScriptSBS\ch20\OneStepFurther\StarterFileForExchangeMailBox.txt and paste them into the For Each...Next statement. When completed, the script will look like the following:

For Each objItem In colItems
  WScript.Echo "AssocContentCount: " & objItem.AssocContentCount
  WScript.Echo "Caption: " & objItem.Caption
  WScript.Echo "DateDiscoveredAbsentInDS: " _
    & objItem.DateDiscoveredAbsentInDS
  WScript.Echo "DeletedMessageSizeExtended: " _
    & objItem.DeletedMessageSizeExtended
  WScript.Echo "Description: " & objItem.Description
  WScript.Echo "InstallDate: " & objItem.InstallDate
  WScript.Echo "LastLoggedOnUserAccount: " _
    & objItem.LastLoggedOnUserAccount
  WScript.Echo "LastLogoffTime: " & objItem.LastLogoffTime
  WScript.Echo "LastLogonTime: " & objItem.LastLogonTime
  WScript.Echo "LegacyDN: " & objItem.LegacyDN
  WScript.Echo "MailboxDisplayName: " & objItem.MailboxDisplayName
  WScript.Echo "MailboxGUID: " & objItem.MailboxGUID
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "ServerName: " & objItem.ServerName
  WScript.Echo "Size: " & objItem.Size
  WScript.Echo "Status: " & objItem.Status
  WScript.Echo "StorageGroupName: " & objItem.StorageGroupName
  WScript.Echo "StorageLimitInfo: " & objItem.StorageLimitInfo
  WScript.Echo "StoreName: " & objItem.StoreName
  WScript.Echo "TotalItems: " & objItem.TotalItems
  WScript.Echo "-=-"
Next

12.
Save and run your script using CScript. If the script has problems, compare your script to \My Documents\Microsoft Press\VBScriptSBS\ch20\OneStepFurther\ExchangeMailbox.vbs.

Chapter 20 Quick Reference

To

Do This

Manage and monitor Exchange 2003 using WMI

Use the classes found in the MicrosoftExhangeV2 namespace

Connect to the MicrosoftExchangeV2 namespace

Use GetObject and the WMI moniker; also specify the target computer and the root\MicrosoftExchangeV2 namespace

Obtain information about Exchange 2003 public folders

Query the Exchange_PublicFolder class in the root\MicrosoftExchangeV2 namespace



Previous Page
Next Page