MAPI Logon Check script (Task and Diagnostic)

Microsoft.Exchange.2003.MAPILogonCheck (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script ProbeAction System.Secure.CommandExecuterProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<ProbeActionModuleType ID="Microsoft.Exchange.2003.MAPILogonCheck" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false" PassThrough="false">
<Configuration>
<xsd:element name="TargetNetbiosComputer" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="System!System.Secure.CommandExecuterProbe">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/MAPILogonCheck.js$ $Config/TargetNetbiosComputer$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>MAPILogonCheck.js</Name>
<Contents><Script>
// Event Constants
var EVENT_SOURCE = "Exchange MOM";
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;

var oAPI = new ActiveXObject("Mom.ScriptAPI");

function CreateEvent(lngEventID, lngEventType, strMsg)
{
oAPI.LogScriptEvent(EVENT_SOURCE, lngEventID, lngEventType, strMsg);
}

function EchoEvent(lngEventID, lngEventType, strMsg)
{
var sevString;

switch(lngEventType)
{
case EVENT_TYPE_SUCCESS: sevString = "Success"; break;
case EVENT_TYPE_ERROR: sevString = "Error"; break;
case EVENT_TYPE_WARNING: sevString = "Warning"; break;
case EVENT_TYPE_INFORMATION: sevString = "Infomation"; break;
}

if (lngEventType != EVENT_TYPE_SUCCESS)
{
WScript.Echo(EVENT_SOURCE , "Event ID:" , lngEventID , "Severity: " , sevString);
WScript.Echo(strMsg);
}
}

function HResultToString(hresult)
{
return "0x" + (hresult &lt; 0 ? hresult + 0x100000000 : hresult).toString(16).toUpperCase() + "(" + hresult +")";
}


//Copyright (c) Microsoft Corporation. All rights reserved.
//*************************************************************
// $ScriptName: "MAPI logon verification" $
//
// Events created by this script:
// SOURCE ID TYPE DESCRIPTION
// Exchange MOM 9980 none Logon Successful
// Exchange MOM 9981 error General MAPI logon failure
// Exchange MOM 9982 error Problem in accessing Exchange Store
// Exchange MOM 9983 error Cannot verify availability of the following test account
// Exchange MOM 9984 error Cannot measure server availability: the script is not running as LocalSystem
// Exchange MOM 9985 error Cannot measure server availability: error verifying the script context
// Exchange MOM 5987 inform Attempting to publish Exchange Management Pack data
// Exchange MOM 5988 inform Please run Exchange Management Pack Configuration Utility
// Exchange MOM 9989 error Logon to the Exchange Store timed out
// Exchange MOM 5990 error Cannot measure server availability: error verifying pub key
// Exchange MOM 9991 error Cannot measure server availability: failed to determine if computer is a front-end server
// Exchange MOM 9996 warning Mailbox is not residing on the proper server
// Exchange MOM 9997 error Encounter problem when accessing the AD to find test accounts
// Exchange MOM 9998 error Cannot check availability due to unexpected Error
// Exchange MOM 9999 error WMI is not running
// Exchange MOM 19998 none All attempted logins succeed
//
// Performance Counter created by this script
// Exchange MP \ MAPI Logon Status
// Exchange MP \ MAPI Logon Latency (seconds)
// --&gt; this counter is only created if the LogPerfData parameter of this script is set to 1
//
// $File: MAPI_Logon_Verification.js $
//*************************************************************

// Event Constants
EVENT_SOURCE = "MAPI logon verification";
// Event ID Constants
var EVENT_ID_BASE_STATE_OK = 10000;

// TypedPropertyBag
var PerformanceDataType = 2;
var StateDataType = 3;

var LogPerfData,TargetNetbiosComputer;
if(WScript.Arguments.Unnamed.Count == 1)
{
TargetNetbiosComputer=WScript.Arguments(0);
}
else
{
WScript.Echo ("Script requires 1 parameter: &lt;Target Computer Name&gt;");
WScript.quit();
}


function IsWMIRunning()
{
var ERR_ID = 9013;
var ERR_MSG = "The 'Windows Management Instrumentation' service (WinMgmt.exe) was not running when MOM tried to run a script that is dependent on this service. Check if the start up mode of this service is not set to 'disabled'.";
var blnRet = true;
try {
var objWMI = GetObject("winmgmts:root\\cimv2");
}
catch(err) {
EchoEvent(ERR_ID, EVENT_TYPE_ERROR, ERR_MSG);
blnRet = false;
}
return(blnRet);
}

// The caller is responsible for the exception treatment
function IsRunningAsSystem()
{
var retval = false;
var WshNetwork = new ActiveXObject("WScript.Network");
// Use the well-known SID of the system account ("S-1-5-18") to get the correspondent object
var WMISystemAcct = GetObject("WinMgmts:root/cimv2:Win32_SID='S-1-5-18'");
// WshNetwork.UserName gives the account running the current thread
//
// WMISystemAcct.AccountName gets the localized name of the system account
//
// No worries with string case in the comparison below since, if the account is
// system, the name is extracted from the same location for both objects
if (WshNetwork.UserName == WMISystemAcct.AccountName)
retval = true;
return(retval);
}

function IsFrontEnd(strServerName)
{
var oConnect = new ActiveXObject("ADODB.Connection");
oConnect.Provider = "ADsDSOObject";
oConnect.Open();
var command = new ActiveXObject("ADODB.Command");
command.ActiveConnection = oConnect;
var objRootDSE = GetObject("LDAP://rootDSE");
command.CommandText = "SELECT CN FROM 'LDAP://" + objRootDSE.Get("configurationNamingContext") + "' WHERE CN='" + strServerName + "' AND serverRole=1";
command.Properties("Page Size") = 100;
command.Properties("Timeout") = 10;
command.Properties("searchscope") = 2;
command.Properties("Chase referrals") = 0x20 | 0x40;
command.Properties("Cache Results") = false;
var rs = command.Execute();
var boolIsFrontEnd = false;
if (!rs.EOF){
rs.MoveFirst();
if (rs.Fields(0).Value.toUpperCase() == strServerName.toUpperCase())
boolIsFrontEnd = true;
}
return boolIsFrontEnd;
}
function IsKeyPublished()
{
var bRet;
var WshShell = new ActiveXObject("WScript.Shell");
var data = null;
try{
data = WshShell.RegRead("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\ExMPLS\\DATA0");
}catch(err){
if (-2147024894 != err.number) // If not Invalid entry or key throw the error
throw err;
data = null;
}
bRet = false;
try{
if ((null != data) &amp;&amp;
("unknown" == typeof(data)) &amp;&amp;
(256 &lt;= (data.ubound() - data.lbound() + 1)))
{
var jsArray = data.toArray();
if ("number" == typeof(jsArray[0]))
bRet = true;
}
}catch(err){
// data is not the expected structure
bRet = false;
}
return bRet;
}
function GetPercentProcessorTime()
{
var objWMI, PercentProcessorTime, perf_instance1, perf_instance2, N1, D1, N2, D2, objUtil;
try{
objWMI = GetObject("Winmgmts:Root\\Cimv2");
}catch(err){ return -1;};
PercentProcessorTime = 0;
for(var i = 0; i&lt;5; i++)
{
perf_instance1 = null;
perf_instance2 = null;
N1 = 0;
D1 = 0;
N2 = 0;
D2 = 0;
try{ perf_instance1 = objWMI.Get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'");}catch(err2){return -1;};
N1 = perf_instance1.PercentProcessorTime;
D1 = perf_instance1.TimeStamp_Sys100NS;
//Sleep for 1 second
WScript.Sleep(1000);
try{perf_instance2 = objWMI.Get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'");}catch(err3){return -1;};
N2 = perf_instance2.PercentProcessorTime;
D2 = perf_instance2.TimeStamp_Sys100NS;
//CounterType: PERF_100NSEC_TIMER_INV
//Formula: (1- ((N2 - N1) / (D2 - D1))) x 100
if ((D2-D1)&gt;0)
PercentProcessorTime = (1 - ((N2 - N1)/(D2-D1)))*100 + PercentProcessorTime;
else
return -1;
}
PercentProcessorTime = PercentProcessorTime / 5;
return PercentProcessorTime;
}
function IsServiceUp(strServiceName)
{
////Check whether a service is up////////////////////////////////////////////////////////////////////////
var boolServiceRunning = false;
var objServiceSet = GetObject("winmgmts://./root/cimv2").ExecQuery("select * from Win32_Service where name='" + strServiceName + "' and Started=True");
var enumService = new Enumerator (objServiceSet);
for (;!enumService.atEnd();enumService.moveNext ())
{
if (enumService.item().name.toLowerCase() == strServiceName)
boolServiceRunning = true;
}
return boolServiceRunning;
}
function GetRootGC()
{
var oGCColl = GetObject("GC:");
var enumGCs = new Enumerator(oGCColl);
if (!enumGCs.atEnd())
return enumGCs.item();
return null;
}
// Note that elements are 'trimmed' and if str == """ the array will be { "" }
function SplitParams(str)
{
var objRegExp = /[,\s]+/;
var objArray = str.split(objRegExp);
return(objArray);
}
// Not all event messages are declared here check the CreateEvent calls to see the event messages
var UNEXPECTED_EXCEPTION_EVENT_ID = 9998;
var UNEXPECTED_EXCEPTION_EVENT_MSG = "Cannot measure server availability: unexpected error:\n";
var NO_UNEXPECTED_EXCEPTION_EVENT_ID = EVENT_ID_BASE_STATE_OK + UNEXPECTED_EXCEPTION_EVENT_ID;
var NO_UNEXPECTED_EXCEPTION_EVENT_MSG = "No unexpected exceptions";
var FAILED_TO_SET_COMP_DATA_ID = 9998;
var FAILED_TO_SET_COMP_DATA_MSG = "Cannot update the MAPI Logon state component on MOM for this computer.\nError:\n";
var WMI_NOT_RUNNING_EVENT_ID = 9999;
var WMI_NOT_RUNNING_MSG = "Cannot measure server availability: the 'Windows Management Instrumentation' service (WinMgmt.exe) was not running when MOM tried to run a script that is dependent on this service. Check if the start up mode of this service is not set to 'disabled'.";
var LOGON_SUCCESS_EVENT_ID = 9980;
var ALL_LOGONS_OK_EVENT_ID = 19980;
var ALL_LOGONS_OK_EVENT_MSG = "All attempted logins of test mailboxes residing on this server succeed.";
var CANNOT_RUN_AS_SYSTEM_EVENT_ID = 9984;
var CANNOT_RUN_AS_SYSTEM_EVENT_MSG = "Cannot measure server availability: the script is not running as LocalSystem";
var AGENT_ACCT_CHECK_FAILED_ID = 9985;
var AGENT_ACCT_CHECK_FAILED_MSG = "Cannot measure server availability: error verifying the script context\nError:\n";
var SERVER_ROLE_CHECK_FAILED_ID = 9991;
var SERVER_ROLE_CHECK_FAILED_MSG = "Cannot measure server availability: error accessing the Active Directory when trying to determine if the current computer is a front-end server\nError:\n";
var CALL_PUBLISH_EXMP_ID = 5987;
var CALL_PUBLISH_EXMP_MSG = "Attempting to publish Exchange Management Pack data required to use the test mailbox accounts";
var CALL_CONFIGAPP_ID = 5988;
var CALL_CONFIGAPP_MSG = "Please run Exchange Management Pack Configuration Utility against this Exchange Server";
var VERIFY_PUBLISH_FAILED_ID = 5990;
var VERIFY_PUBLISH_FAILED_MSG = "Cannot measure server availability: error checking the Exchange Management Pack data required to use the test mailbox accounts\nError:\n";
var TST_MB_ON_WRONG_SERVER_ID = 9996;
var GENERAL_MAPI_LOGON_FAILURE_ID = 9981;
var PROBLEM_ACCESSING_STORE_ID = 9982;
var FAILED_TO_VERIFY_AVAIL_OF_TST_ACCT_ID = 9983;
var GET_TST_MB_FAILED_ID = 9997;
var GET_TST_MB_FAILED_MSG = "Cannot measure server availability: error when trying to find the associated test accounts from the Active Directory \n" +
"Please make sure the Domain Controller is running properly and can be accessed from this server.\n" +
"Please also make sure an Exchange mailbox is created for the test account.\nError: ";
var TIME_OUT_THRESHOLD = 30000;
// Other Constants
var LOGON_SUCCESS = 0;
var MAPI_E_LOGON_FAILED = -2147219719; //CDO type constant [0x80040111] or 1273
var MAPI_E_FAILONEPROVIDER = -2147219707; //CDO type constant [0x8004011D] or 1285
var MAPI_E_SESSIONLIMIT = -2147219718; //CDO type constant [0x80040112] or 1274
var MAPI_E_NOT_ENOUGH_RESOURCES = -2147219722; //CDO type constant [0x8004010E] or 1270
var MAPI_E_NOT_ENOUGH_MEMORY = -2147219978; //CDO type constant [0x800700E] or 1014
var LOGON_TIMEOUT = 7005;
var CallPublishEvent = 8000;
var CallConfigurationUtility = 8001;
var ERROR_FILE_NOT_FOUND = -2147024894;
// Declare Vars
var arrAccount;
var i, arrE2KSrvs, objResult;
var bLogPerfData = true;
var bCreateSuccessEvent = false;
var bAllLogonsSucceed = true;
var bMapiLogonConfigured = false;
var iLogPerfDataParam = LogPerfDataEnabled();
// When LogPerfDataEnabled()
// equals to 1 then log perf data, but don't create success event
// equals to 0 then don't log perf data, but do create success event
// equals to -1 then don't log perf data and don't create success event
// equals to neither 0, 1 nor -1 then set to default (0 - don't log perf data, but do create success event)
if (iLogPerfDataParam == 1)
bLogPerfData = true;
else
if (iLogPerfDataParam == 0)
bCreateSuccessEvent = true;
else
if (iLogPerfDataParam != -1)
bCreateSuccessEvent = true;
MainRoutine:
{
try
{
arrAccount = FindTestAccount(TargetNetbiosComputer);
}
catch(err)
{
EchoEvent(GET_TST_MB_FAILED_ID, EVENT_TYPE_ERROR, GET_TST_MB_FAILED_MSG + HResultToString(err.number) + " " + err.description);
break MainRoutine;
}
bMapiLogonConfigured = ((arrAccount != null) &amp;&amp; (arrAccount.length &gt; 0));
// If not configured generate the appropriate events to update the state
if (!bMapiLogonConfigured)
{
EchoEvent(ALL_LOGONS_OK_EVENT_ID, EVENT_TYPE_SUCCESS, ALL_LOGONS_OK_EVENT_MSG);
EchoEvent(NO_UNEXPECTED_EXCEPTION_EVENT_ID, EVENT_TYPE_SUCCESS, NO_UNEXPECTED_EXCEPTION_EVENT_MSG);
}
// If not configured bail out -this should be done only after generating the appropriate events and disabling the component
if (!bMapiLogonConfigured)
break MainRoutine;
if (!IsWMIRunning())
{
EchoEvent(WMI_NOT_RUNNING_EVENT_ID, EVENT_TYPE_ERROR, WMI_NOT_RUNNING_MSG);
break MainRoutine;
}
try
{
if (!IsKeyPublished())
{
EchoEvent(CALL_PUBLISH_EXMP_ID, EVENT_TYPE_INFORMATION, CALL_PUBLISH_EXMP_MSG);
break MainRoutine;
}
}
catch(err)
{
EchoEvent(VERIFY_PUBLISH_FAILED_ID, EVENT_TYPE_ERROR, VERIFY_PUBLISH_FAILED_MSG + HResultToString(err.number) + " " + err.description);
break MainRoutine;
}

LogonVerification(TargetNetbiosComputer);
}//MainRoutine

function LogonVerification(strServer)
{
try{
if (!IsRunningAsSystem())
{
EchoEvent(CANNOT_RUN_AS_SYSTEM_EVENT_ID, EVENT_TYPE_ERROR, CANNOT_RUN_AS_SYSTEM_EVENT_MSG);
return;
}
} catch(err) {
EchoEvent(AGENT_ACCT_CHECK_FAILED_ID, EVENT_TYPE_ERROR, AGENT_ACCT_CHECK_FAILED_MSG + HResultToString(err.number) + " " + err.description);
return;
}
try{
if (IsFrontEnd(strServer)) return;
} catch(err) {
EchoEvent(SERVER_ROLE_CHECK_FAILED_ID, EVENT_TYPE_ERROR, SERVER_ROLE_CHECK_FAILED_MSG + HResultToString(err.number) + " " + err.description);
return;
}
try{
if (arrAccount != null){
arrAccount = RemoveMultipleMailboxOnSameMDB(arrAccount);
for(i in arrAccount){
if (arrAccount[i].ServerName.toUpperCase() != strServer.toUpperCase())
EchoEvent(TST_MB_ON_WRONG_SERVER_ID, EVENT_TYPE_WARNING, "Mailbox " + arrAccount[i].Account + " is being used for testing availability (through MAPI logon) and it is not residing on the server: " + strServer + ".\n MAPI logon test will not be performed against this mailbox.\n Please move mailbox back to " + strServer + " or delete this mailbox");
else
if (CDOLogon(strServer, arrAccount[i]) == "Quit")
return;
// By default LogonSucceed is false, CDOLogon sets it to true only if the logon was performed without problems
bAllLogonsSucceed &amp;= arrAccount[i].LogonSucceed;
}
}
if (bAllLogonsSucceed)
EchoEvent(ALL_LOGONS_OK_EVENT_ID, EVENT_TYPE_SUCCESS, ALL_LOGONS_OK_EVENT_MSG);
} catch(err){
oBag= oAPI.CreateTypedPropertyBag(StateDataType) ;
oBag.AddValue("State","BAD");
oAPI.AddItem(oBag);
EchoEvent(UNEXPECTED_EXCEPTION_EVENT_ID, EVENT_TYPE_ERROR, UNEXPECTED_EXCEPTION_EVENT_MSG + HResultToString(err.number) + " " + err.description);
return;
}

EchoEvent(NO_UNEXPECTED_EXCEPTION_EVENT_ID, EVENT_TYPE_SUCCESS, NO_UNEXPECTED_EXCEPTION_EVENT_MSG);
}
// Performs the logon operation, if the operation succeeds sets the LogonSucceed property of objAccount to true
function CDOLogon(strServerName, objAccount)
{
var objML;
var errID = null;
var boolStoreRunning = true;
var boolMDBMounted = true;
var boolLogonSucceeded = false;
var MiscErrorDesc = "";
var objShell, err2, err3, fPercentProcessorTime;
var Latency, objDateStart, objDateEnd;
objML = new ActiveXObject("EMPML.MapiLogonVerifier");
//get logon start time
objDateStart = new Date();
Latency = objDateStart.getTime();
//Do MAPI logon
try{
errID = objML.Logon(strServerName, objAccount.Account, TIME_OUT_THRESHOLD);
}catch(err2){
try {
objShell = new ActiveXObject("WScript.Shell");
//objML would set the reg value MLTimeOut prior to termination if it is a time out
if (objShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\ExMPLS\\MLTimeOut") == "Y")
errID = LOGON_TIMEOUT;
} catch(err3) {
//some unknown error caused the object to terminate, throw error
throw err2;
}
}
//get logon end time
objDateEnd = new Date();
Latency = ( objDateEnd.getTime() - Latency ) / 1000; //convert time from millisecond to second
//report and further diagnose logon result
if (errID == LOGON_SUCCESS){
objAccount.LogonSucceed = true;
if(bCreateSuccessEvent)
EchoEvent(LOGON_SUCCESS_EVENT_ID, EVENT_TYPE_SUCCESS, "Logon to Exchange Server is successful\nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB + "\"\nMailbox:\""+ objAccount.Account +"\"");
WScript.Echo("MAPI Logon is successful for" , objAccount.StorageGroup , "\\" , objAccount.HomeMDB);
WScript.Echo("MAPI Logon Latency is: " , Latency , " sec");
}
else
{
//MAPI_E_LOGON_FAILED occurs when the client was not able to contact the DS to authenticate
if (errID == MAPI_E_LOGON_FAILED) //0x80040111 or 1273
{
EchoEvent(GENERAL_MAPI_LOGON_FAILURE_ID, EVENT_TYPE_ERROR, "Problem in accessing Directory Service caused Logon failure\nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB + "\"\nMailbox:\""+ objAccount.Account +"\"\nError: \n" + objML.ErrDes);
}
// MAPI_E_FAILONEPROVIDER is the error when we have any of these conditions:
// 1. mdb is dismounted
// 2. store is stopped
// 3. store is hung (e.g. in the debugger)
else if ( errID == MAPI_E_FAILONEPROVIDER || //8004011D or 1285
errID == MAPI_E_SESSIONLIMIT || //80040112 or 1274
errID == MAPI_E_NOT_ENOUGH_RESOURCES || //8004010E or 1270
errID == MAPI_E_NOT_ENOUGH_MEMORY) //8007000E or 1014
{
//oBag= oAPI.CreateTypedPropertyBag(StateDataType) ;
//oBag.AddValue("State","BAD");
//oAPI.AddItem(oBag);
try{
boolStoreRunning = IsServiceUp("msexchangeis");
if (boolStoreRunning) {
try{
boolMDBMounted = CheckMDB(objAccount.HomeMDBPath);
}catch(err2){ MiscErrorDesc = "Cannot check the state of MDB through CDOEXM due to error: " + HResultToString(err2.number) + " " + err2.description; }
}
}
catch(err2){ MiscErrorDesc = "Cannot check the state of Exchange Information Store Service through WMI due to error: " + HResultToString(err2.number) + " " + err2.description; }

if (!boolStoreRunning)
EchoEvent(
PROBLEM_ACCESSING_STORE_ID,
EVENT_TYPE_ERROR,
"Problem in accessing the Exchange Information Store\nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB +"\"\nMailbox:\""+ objAccount.Account + "\"\nError: Microsoft Exchange Information Store service is NOT running\n" + objML.ErrDes);
else if (!boolMDBMounted)
EchoEvent(
PROBLEM_ACCESSING_STORE_ID,
EVENT_TYPE_ERROR,
"Problem in accessing the Exchange Information Store\nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB +"\"\nMailbox:\""+ objAccount.Account + "\"\nError: MDB is not mounted \n" + objML.ErrDes);
else
EchoEvent(
PROBLEM_ACCESSING_STORE_ID,
EVENT_TYPE_ERROR,
"Problem in accessing the Exchange Store\nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB + "\"\nMailbox:\""+ objAccount.Account + "\"\nError: \n" + objML.ErrDes + "\n\nAdditional diagnosis on the problem can't be perform because:\n" + MiscErrorDesc);
}
else if (errID == CallPublishEvent){
EchoEvent(CALL_PUBLISH_EXMP_ID, EVENT_TYPE_INFORMATION, CALL_PUBLISH_EXMP_MSG);
return "Quit";
}
else if (errID == CallConfigurationUtility){
EchoEvent(CALL_CONFIGAPP_ID, EVENT_TYPE_INFORMATION, CALL_CONFIGAPP_MSG);
return "Quit";
}
else if (errID == LOGON_TIMEOUT){
fPercentProcessorTime = GetPercentProcessorTime();
if (fPercentProcessorTime &gt;= 0)
EchoEvent(
GENERAL_MAPI_LOGON_FAILURE_ID,
EVENT_TYPE_ERROR,
"Logon to the Exchange Store timed out at the " + TIME_OUT_THRESHOLD/1000 + " seconds threshold \nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB + "\"\nMailbox:\""+ objAccount.Account + "\"\nCPU is running at " + fPercentProcessorTime.toFixed(2) + " percent");
else
EchoEvent(
GENERAL_MAPI_LOGON_FAILURE_ID,
EVENT_TYPE_ERROR,
"Logon to the Exchange Store timed out at the " + TIME_OUT_THRESHOLD/1000 + " seconds threshold \nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB + "\"\nMailbox:\""+ objAccount.Account + "\"");

WScript.Echo("MAPI Logon is successful for" , objAccount.StorageGroup , "\\" , objAccount.HomeMDB);
WScript.Echo("MAPI Logon Latency is: " , Latency , " sec");
}
else // Record all other errors
{
EchoEvent(
FAILED_TO_VERIFY_AVAIL_OF_TST_ACCT_ID,
EVENT_TYPE_ERROR,
"Cannot verify availability of the following test account: \nExchange Server:\"" + strServerName + "\"\nMDB:\"" + objAccount.StorageGroup + "\\" + objAccount.HomeMDB +"\"\nMailbox:\""+ objAccount.Account + "\"\ndue to the following error \nError ID: " + HResultToString(errID) + "\nError text: " + objML.ErrDes);
}
}
}
function CheckMDB(strMDBPath)
{
var intRetry = 0;
var objMailboxStore = new ActiveXObject("CDOEXM.MailboxStoreDB");
do{
try{
objMailboxStore.DataSource.Open(strMDBPath);
if (objMailboxStore.Status == 1) return false;
else return true;
} catch(err){ intRetry++;}
}while(intRetry&gt;0 &amp;&amp; intRetry&lt;2);
throw err;
}
function FindTestAccount(strServerName)
{
var objShell = null;
var strAccounts = null;
var arrAccountNames = new Array();
var accountSelect = null;
var testServerMailbox_RegPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Exchange MOM\\Accounts\\"+strServerName+"\\TestServerMailbox";
var mdbMailboxNames_RegPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Exchange MOM\\Accounts\\"+strServerName+"\\MDBMailboxNames";
objShell = new ActiveXObject("WScript.Shell");
try
{
strAccounts = objShell.RegRead(mdbMailboxNames_RegPath);
//Deals with the case when the value was created but not touched
// in which RegRead will return the registry path
if ( strAccounts == mdbMailboxNames_RegPath)
strAccounts = null;
if (strAccounts != null &amp;&amp; strAccounts.length &gt; 0)
//Splits strAccounts by commas and trims any whitespaces in account names
arrAccountNames = SplitParams(strAccounts);
}
catch(err)
{
// If error is not ERROR_FILE_NOT_FOUND (i.e. RegKey doesn't exist) then throw error
if (ERROR_FILE_NOT_FOUND != err.number)
throw err;
}
strAccounts = null;
try
{
strAccounts = objShell.RegRead(testServerMailbox_RegPath);
strAccounts = strAccounts.replace(/(^\s+)|(\s+$)/g, ""); //Trim white spaces
//Deals with the case when the value was created but not touched
// in which RegRead will return the registry path
if ( strAccounts == testServerMailbox_RegPath)
strAccounts = null;
}
catch(err)
{
// If error is not ERROR_FILE_NOT_FOUND (i.e. RegKey doesn't exist) then throw error
if (ERROR_FILE_NOT_FOUND != err.number)
throw err;
}
if (strAccounts != null &amp;&amp; strAccounts.length &gt; 0)
arrAccountNames.push(strAccounts);
if (arrAccountNames.length &gt; 0)
{
accountSelect = "sAMAccountName='" + arrAccountNames[0] + "'";
for( accountIndex = 1; accountIndex&lt;arrAccountNames.length; accountIndex++)
accountSelect += " OR sAMAccountName='" + arrAccountNames[accountIndex] + "'";
}
else
{
accountSelect = "sAMAccountName='" + DeriveAccountName(strServerName) + "'";
}
var IADsPathname = new ActiveXObject("Pathname");
var oConnect = new ActiveXObject("ADODB.Connection");
oConnect.Provider = "ADsDSOObject";
oConnect.Open();
var command = new ActiveXObject("ADODB.Command");
command.ActiveConnection = oConnect;
var objRootGC = GetRootGC();
command.CommandText = "SELECT homeMDB, AdsPath, sAMAccountName FROM '" + objRootGC.ADsPath + "' WHERE " + accountSelect + " AND objectclass='user' AND objectCategory='person' ORDER BY sAMAccountName";
command.Properties("Page Size") = 100;
command.Properties("Timeout") = 10; //seconds
command.Properties("searchscope") = 2; //ADS_SCOPE_SUBTREE
command.Properties("Chase referrals") = 0x20 | 0x40; //ADS_CHASE_REFERRALS_ALWAYS
command.Properties("Cache Results") = false; //do not cache the result set
var rs = command.Execute();
if (!rs.EOF)
{
var count = 0;
var arrCache = new Array();
rs.MoveFirst();
while (!rs.EOF){
arrCache[count] = new CacheAccount();
for(i = 0; i&lt;rs.Fields.Count; i++){
if (rs.Fields(i).Name == "sAMAccountName") {
arrCache[count].Account = rs.Fields(i).Value;
}
if (rs.Fields(i).Name == "homeMDB") {
IADsPathname.Set(rs.Fields(i).Value, 4); // ADS_SETTYPE_DN
IADsPathname.EscapedMode = 4; // ADS_ESCAPEDMODE_OFF_EX
arrCache[count].HomeMDB = IADsPathname.GetElement(0).substring(3);
arrCache[count].HomeMDBPath = rs.Fields(i).Value;
arrCache[count].StorageGroup = IADsPathname.GetElement(1).substring(3);
arrCache[count].ServerName = IADsPathname.GetElement(3).substring(3);
}
}
rs.MoveNext();
count++;
}
return arrCache;
}
}
function CacheAccount(strAccount, strHomeMDB, strHomeMDBPath, strStorageGroup, strServerName)
{
this.Account = strAccount;
this.HomeMDB = strHomeMDB;
this.HomeMDBPath = strHomeMDBPath;
this.StorageGroup = strStorageGroup;
this.ServerName = strServerName;
this.LogonSucceed = false;
}
function DeriveAccountName(strSrvName)
{
return strSrvName + "MOM*";
}
function RemoveMultipleMailboxOnSameMDB(arrAccount)
//Remove mailbox account that resides on the same MDB
// from the array of mailboxes to be logged on, so that the script
// will only log onto one mailbox per MDB
{
var cAccount, cRet, cRet_LastElement;
var bDistinctMDB;
var arrRet = new Array();
arrRet[0] = arrAccount[0];
cRet_LastElement = 1;
for(cAccount=1; cAccount &lt; arrAccount.length; cAccount++)
{
bDistinctMDB = true;
for(cRet=0; cRet &lt; arrRet.length; cRet++)
{
if( arrAccount[cAccount].StorageGroup.toUpperCase() == arrRet[cRet].StorageGroup.toUpperCase() )
{
if( arrAccount[cAccount].HomeMDB.toUpperCase() == arrRet[cRet].HomeMDB.toUpperCase() )
{
bDistinctMDB = false;
break;
}
}
}
if(bDistinctMDB){
arrRet[cRet_LastElement] = arrAccount[cAccount];
cRet_LastElement++;
}
}//end for
return arrRet;
}
function LogPerfDataEnabled()
{
return 1;
}

</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>