Converting a VBScript for Exchange 2003 to Function the same for Exchange 2010
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 updat
February 4th, 2014 4:44pm

Hi

I can't help you out with VB script but I would guess that this is going to be easier with PowerShell.  Here is an excellent example of a data collection script:

http://www.stevieg.org/2011/06/exchange-environment-report/

Steve

Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 3:10am

Okay, then what about an alternative for getting the same result. The file associated in the article is too much.  All we need is something simple for a single exchange server with 180 users.  We only need to pull UserName and DataSize(KB).

I only need to collect two pieces of information from the exchange server and the third piece is forced due to the date of when the information was collected.  This way I can sort and filter by Date and Name to see a trend of the users mailbox usage size.

Every day this runs, it determines the date of the file which is also the first piece, then pulls from the exchange server the entire list of users (the second piece), and then the respective user's mailbox size in KB (the third piece).  This all is dropped into a CSV file later used to import into a database before being archived, done by a second task on the server.  Later used by a shared Excel PowerPivot document among the department.

Those of us in the server admin group use this to, at a glance, see the collective size of email usage on the server.  Mainly used as a means of catching an incident before it happens.  We are currently keeping our users around a collective 80GB of use out of the well received limit of 110GB on Exchange 2003 and limiting the user's ability to send and receive email by email quota is apparently not accepted for us to do.  So we use this to determine who we need to visit and force archive their email so the server doesn't fail due to the size limit.

February 7th, 2014 4:44pm

This should work for you then:

Get-Mailbox | Get-MailboxStatistics | Select DisplayName,TotalItemSize | Export-CSV c:\temp\yourfile.csv -NoTypeInformantion

The only thing about that Select statement is the TotalItemSize will display as KB/MB/GB to make the output readable ... this can be changed if you need it in KB.

Steve

Free Windows Admin Tool Kit Click here and download it now
February 10th, 2014 4:11am

This should work for you then:

Get-Mailbox | Get-MailboxStatistics | Select DisplayName,TotalItemSize | Export-CSV c:\temp\yourfile.csv -NoTypeInformantion

The only thing about that Select statement is the TotalItemSize will display as KB/MB/GB to make the output readable ... this can be changed if you need it in KB.

Steve

February 10th, 2014 4:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics