Quantcast
Channel: Exchange Server 2013 - Administration, Monitoring, and Performance 论坛
Viewing all articles
Browse latest Browse all 8719

Converting a VBScript for Exchange 2003 to Function the same for Exchange 2010

$
0
0
Converting a VBScript for Exchange 2003 to Function the same for Exchange 2010


Afternoon;

I've run into a problem at this time.  We are currently looking into migrating from Exchange 2003 into Exchange 2010 and I'm finding that my normal data collection method is no longer usable in Exchange 2010.  I have the script posted below as of what I'm currently using to collect my information, I just need to know of a means to continue the collection when we move to the new Exchange server.  Any assistance in getting this to function with Exchange 2010 would be great.

++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++

On Error Resume Next

'Date Stamp for File Name
Function TIMESTAMP
  strDate = CDate(Date)
  strDay = DatePart("d", strDate)
  strMonth = DatePart("m", strDate)
  strYear = DatePart("yyyy", strDate)
  If strDay < 10 Then
    strDay = "0" & strDay
  End If
  If strMonth < 10 Then
    strMonth = "0" & strMonth
  End If
  TIMESTAMP = strYear & strMonth & strDay
End Function

'Drop Location Vars Set
DRP01 = 1
DRP02 = 1

'Live Check SQL04
strVIC = "SQL04"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_PingStatus Where Address = '" & strVIC & "'")
For Each objItem in colItems
    DRP01 = objItem.StatusCode
Next

'Live Check FS02
strVIC = "FS02"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_PingStatus Where Address = '" & strVIC & "'")
For Each objItem in colItems
    DRP02 = objItem.StatusCode
Next

'Setup STOREDIR Location
If DRP01 = 0 Then
    STOREDIR = "\\SQL04\Email\Collected\" 'Primary Data Storage Location
    Else
    If DRP02 = 0 Then
        STOREDIR = "\\FS02\Shared\MIS\Daniel\" 'Secondary Data Storage Location
        Else
        STOREDIR = "C:\Scripts\Logs\" 'Tertiary Data Storage Location
    End If
End If

'STOREDIR Check for Availability
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(STOREDIR) Then
    AVAIL = 1
    Else
    AVAIL = 0
End If

'Sets Failsafe STOREDIR
If AVAIL = 0 Then
    STOREDIR = "C:\Scripts\" 'Last Chance DIR for Data Files
End If

'Sets Filename
FILENAME = TIMESTAMP & ".csv"

'Testing Purposes Only
'wscript.echo TIMESTAMP
'wscript.echo STOREDIR & vbNewLine & FILENAME & vbnewline & vbnewline & AVAIL

'Sets Process Variables
cComputerName = "EXCH02" ' Exchange Server Name or IP Address
DIM fso, ObjFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set ObjFile = fso.CreateTextFile(STOREDIR & FILENAME, True)
'ObjFile.WriteLine("Date,Display Name,Size(KB)")
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Dim strWinMgmts            
Dim objWMIExchange   
Dim listExchange_Mailboxs  
Dim objExchange_Mailbox           
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & cComputerName &"/" & cWMINameSpace
Set objWMIExchange =  GetObject(strWinMgmts)

'Checks for Email Record and Records to File
If Err.Number <> 0 Then
  ObjFile.WriteLine("ERROR:" & VBNEWLINE & Err.Number & VBNEWLINE & Err.Description)
Else
  Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
  If (listExchange_Mailboxs.count > 0) Then
    For Each objExchange_Mailbox in listExchange_Mailboxs
       ObjFile.WriteLine(TIMESTAMP & "," & objExchange_Mailbox.MailboxDisplayName & "," & objExchange_Mailbox.Size)
    Next
  Else
    ObjFile.WriteLine("WARNING: No Exchange_Mailbox instances were returned.")
  End If
End If
ObjFile.Close

VBScript is what I prefer. All scripts must have a kill switch to manage them from a primary location. Mine, is an updater method.

VBScript is what I prefer. All scripts must have a kill switch to manage them from a primary location. Mine, is an updater method.


Viewing all articles
Browse latest Browse all 8719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>