Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exchange script stoped working any ideas as to why?

Status
Not open for further replies.

conan3

MIS
May 6, 2003
65
US

I have a script that was working just fine untill the last patch cycle and now it does not work. Gets access denied errors when trying to access the WMI on the remote machine.

Dave

Patches applied to DC and Exchange servers were

947864, IE Update
948590, GDI
948881, KillBits
941693, Windows Kernal
944338, Vbscript Jscript Remote Exploit
945553, DNS

Here is the code that was working just fine until this week.

Option Explicit
On Error Resume Next

Dim ServerList ' List of computers to check
Dim server ' Current computer to check
Dim fso ' File System Object
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxs ' ExchangeLogons collection
Dim objExchange_Mailbox ' A single ExchangeLogon WMI object
Dim logfile ' Output file

Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Const LOG_FILE = "EMailSize.csv"


'--------------------------------------
' Set up the array of email servers
'--------------------------------------
ServerList = Array("ExchangeClusterNode1.MyDomain","ExchangeClusterNode2.MyDomain")

'--------------------------------------
' Set up log file
'--------------------------------------
set fso = CreateObject("Scripting.FileSystemObject")
Set logfile = fso.CreateTextFile(LOG_FILE)
logfile.WriteLine("""Display Name"",""Mailbox Size (KB)"",""Mailbox TotalItems"",""DateDiscoveredAbsentInDS"", _
""LegacyDN"",""Mailbox StoreName"",""Mailbox ServerName""")


' Create the object string, indicating WMI (winmgmts), using the
' current user credentials (impersonationLevel=impersonate),
' on the computer specified in the constant cComputerName, and
' using the CIM namespace for the Exchange provider.
WScript.Echo "Starting now"

'The rest of the script will fetch mailbox sizes for our servers. Mailbox sizes are in Kilobytes.
For Each server in ServerList
WScript.Echo "Starting " & server & " search."
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & server & "/" & cWMINameSpace
'WScript.Echo strWinMgmts

Set objWMIExchange = GetObject(strWinMgmts)

' Verify we were able to correctly set the object.
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
'The Resources that currently exist appear as a list of
'Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)

' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxs.count > 0) Then
' If yes, do the following:
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxs

' Display the value of the Size property.
logfile.WriteLine("""" & objExchange_Mailbox.MailboxDisplayName & """,""" _
& objExchange_Mailbox.Size & """,""" & objExchange_Mailbox.TotalItems & """,""" _
& objExchange_Mailbox.DateDiscoveredAbsentInDS & """,""" & objExchange_Mailbox.LegacyDN _
& """,""" & objExchange_Mailbox.StoreName & """,""" & objExchange_Mailbox.ServerName & """")
Next
Else
' If no Exchange_Mailbox instances were returned, display that.
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
End If
End If
Next

Wscript.Echo "Completed"


This is another simple script that does not work on the domain controllers or exchange servers, but works fine on member servers.

I think the problem is related.

strComputer = "MemberServer1"
'strComputer = "DomainController1"
'strComputer = "ExchangeServer1"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcessList
Wscript.Echo "Process Name: " & objProcess.Name
Next
 

Found it.

sorry didn't get back here sooner to post it.

Microsoft Exchange Management service was not running on all nodes of the cluster.

Turned it back on and everthing worked again.

Now I just need to figure out why the service was not started/stopped.

Dave



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top