Know your ISP.

User #30969   219 posts
Forum Regular

Wanting to run a script as a scheduled task at the end of the month that collects the displayname and mailbox size for each mailbox on an Exchange server.

Will be running it locally, so can do
strComputer = "."

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

To get to the local exchange instance.

Then
Set colItems = objWMIService.ExecQuery ("Select * from Exchange_Mailbox")
To select each mail box?

Then
For Each objItem in colItems
Allows me to interact with the properties? of each mailbox.

So to interact with the name and size I would use?
objItem.MailboxDisplayName
objItem.Size

Ok, so how do I put all this together to pull each mailbox name and associated mailbox size and dump it into an excel spreadsheet? Or .csv file?

posted 2007-Oct-17, 8pm AEST
User #61010   15003 posts
Whirlpool Forums Addict

That's easy..

You are pretty spot on with what you have so far, with the only bits remaining are setting up a FileSystemObject, creating a file, and writing to that file, closing it.

Oh, don't forget, Next after For :).

You should be able to Google for the FSO, and to write a CSV, you can do that easily, just concatenate a string and write the string out to file.

Reset the string after the data is written so that it doesn't duplicate or concat.

posted 2007-Oct-17, 8pm AEST
User #30969   219 posts
Forum Regular

Will this work?
Not sure how to concatenate a string, can I just create the file first, and write directly to the file in the for each next loop?

Set objFSO = CreateObject("Scripting.FileSystem­ Object")
Set objResultsFile = objFSO.CreateTextFile("C:\stuff\ma­ ilboxes.csv", True)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftExchangeV2")
Set colItems = objWMIService.ExecQuery ("Select * from Exchange_Mailbox")

For Each objItem in colItems
objResultsFile.Write objItem.MailboxDisplayName & ","
objResultsFile.Write objItem.Size
objResultsFile.Writeline
Next

objResultsFile.Close

posted 2007-Oct-18, 2am AEST
edited 2007-Oct-18, 2am AEST
User #30969   219 posts
Forum Regular

Yep, it worked.

Dumped a mailboxes.csv to "C:\stuff\

With users names and mailbox sizes. Excellent.

Thanks for your input, re: FSO, for next etc. Much appreciated.

posted 2007-Oct-18, 3am AEST
Hosted by
WebCentral Australia
Big numbers
975,817 threads
17,201,202 posts
2,008,265 whims sent
3,081 wiki topics
235 ISPs listed
8,129 broadband plans
824 modems & routers
40,569 features filled