Monday, January 28, 2008

Exchange White Space Script 1221



There are many scripts available to determine the whitespace on exchange server. Here is another one very simple. All you need to do it to copy and paste below code into notepad, and save it as any name you want, I renamed it "ExchangeWhiteSpaceReport.vbs" and save it to anywhere you want and just run it by double clicking on it. The Script will create a folder on your C drive as follows

Const TEMP_FILE = "C:\scripts\whitespace.txt

Only thing need to be changed it the server name, my server name is as follows rcoevschi001, change this to your own server name

arrComputers = Array("rcoevschi001")

Const TEMP_FILE = "C:\scripts\whitespace.txt"

Const ForWriting = 2

Dim strInput, fso

Set fso = CreateObject("Scripting.FileSystemObject")

Set filDest = fso.OpenTextFile(TEMP_FILE, ForWriting, True)

For Each strComputer In arrComputers

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

Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where Logfile='Application' and Eventcode = '1221'")

For each objEvent in colItems

strMessage = objEvent.Message

StartWhiteSpaceDBName = Instr(1,strMessage,"database",1)

EndWhiteSpaceDBName = Instr(1,strMessage,"has",1)

ReturnDBNameLength = ((EndWhiteSpaceDBName-1)-(StartWhiteSpaceDBName+9))

strWSDB = Mid(strMessage,(StartWhiteSpaceDBName+9),(ReturnDBNameLength))

StartWhiteSpaceSize = Instr(1,strMessage,"has",1)

EndWhiteSpaceSize = Instr(1,strMessage,"megabytes",1)

ReturnSizeLength = ((EndWhiteSpaceSize-1)-(StartWhiteSpaceSize+4))+10

strWSSize = Mid(strMessage,(StartWhiteSpaceSize+4),(ReturnSizeLength))

dtmEventDate = objEvent.TimeWritten

strWSTime = WMIDateStringToDate(dtmEventDate)

strOutput = strWSTime & "," & strComputer & "," & strWSDB & "," & strWSSize

filDest.WriteLine strOutput

Next

Next

filDest.Close

Function WMIDateStringToDate(dtmEventDate)

WMIDateStringToDate = CDate(Mid(dtmEventDate, 5, 2) & "/" & Mid(dtmEventDate, 7, 2) & "/" & Left(dtmEventDate, 4) )

End Function


 

Thanks,

Oz ozugurlu

MCITP (EMA), MCITP (SA),

MCSE (M+, S+) MCDST

Security+, Server +, Project+

4 comments:

A.S said...

The sccript works fine, but it reports all 1221 events in the application log,could you modify it to report only the last time 1221 was written, ie:- The last time exchange maintenance was run.

Anonymous said...

Hello and Thanks!

I agree with Avinash.
Could you add a function Date() or something ?

+ an HTML output in columns ;-)

Would be perfect !!

Anonymous said...

You could use the selection criteria from this script:

Private Sub Main()
Dim sQuery As String
Dim dtmStartDate As Date
Dim dtmEndDate As Date
Dim colItems As Object
Dim objWMIService As Object
Dim objEntry As Object
Set objWMIService = GetObject("winmgmts:")
dtmStartDate = DateAdd("h", -24, Now)
dtmEndDate = Now
' always format dates in queries to avoid locale problems
sQuery = "SELECT * FROM Win32_NTLogEvent Where TimeWritten >= '" & _
Format$(dtmStartDate, "yyyy-mm-dd hh:nn:ss") & _
"' and TimeWritten < '" & Format$(dtmEndDate, "yyyy-mm-dd hh:nn:ss") & _
"' and Logfile='System' and eventcode= 105"
' bit flags are best combined with Or, not +
Set colItems = objWMIService.ExecQuery(sQuery, "WQL", _
wbemFlagReturnImmediately Or wbemFlagForwardOnly)
Debug.Print sQuery
For Each objEntry In colItems
Debug.Print objEntry.timewritten, objEntry.LogFile, objEntry.EventCode
Next
Set colItems = Nothing
Set objWMIService = Nothing
End Sub

ADV Movers said...

Best Moving Company +971 50 3605353

We are Cheap Movers in Dubai, providing best moving

services at reasonable prices. Call Now for Residential and Commercial Dubai Movers +971503605353

Dubai Movers
Movers Dubai
moving services dubai
moving company
movers dubai
home movers dubai
Packer in Dubai
Local Movers
Cheap Movers in Dubai
Dubai Local Movers

http://www.advmovers.com/