Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Get the Mailboxes as per the storage to a file

Hi,

Is there a way to get the mailboxes names and other details as per the storage to a csv or txt file.

regards
Sharath
Avatar of William Elliott
William Elliott
Flag of United States of America image

not tested



Const strtextfile = "C:\results.csv"

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
        "\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Exchange_Mailbox")

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.OpenTextFile(strtextfile,8,True)

For Each objItem in colItems
Header =       "Associated content count" & vbtab & _
                  "Date discovered absent in directory service: " & vbtab & _
                  "Delete messages size extended " & vbtab & _
                  "Last logged-on user account " & vbtab & _
                  "Last logoff time" & vbtab & _
                  "Last logon time" & vbtab & _
                  "Legacy distinguished name" & vbtab & _
                  "Mailbox display name" & vbtab & _
                  "Mailbox GUID" & vbtab & _
                  "Server name" & vbtab & _
                  "Size" & vbtab & _
                  "Storage group name" & vbtab & _
                  "Storage limit information" & vbtab & _
                  "Store name" & vbtab & _
                  "Total items" & vbcrlf

For Each objItem in colItems
changenull(objitem)
results = results & changenull(objItem.AssocContentCount) & vbtab
results = results & changenull(objItem.DateDiscoveredAbsentInDS) & vbtab
results = results & changenull(objItem.DeletedMessageSizeExtended) & vbtab
results = results & changenull(objItem.LastLoggedOnUserAccount) & vbtab
results = results &      changenull(objItem.LastLogoffTime) & vbtab
results = results & changenull(objItem.LastLogonTime) & vbtab
results = results & changenull(objItem.LegacyDN) & vbtab
results = results & changenull(objItem.MailboxDisplayName) & vbtab
results = results & changenull(objItem.MailboxGUID) & vbtab
results = results & changenull(objItem.ServerName) & vbtab
results = results & changenull(objItem.Size) & vbtab
results = results & changenull(objItem.StorageGroupName) & vbtab
results = results & changenull(objItem.StorageLimitInfo) & vbtab
results = results & changenull(objItem.StoreName) & vbtab
results = results & changenull(objItem.TotalItems) & vbcrlf

oOutput.Write(Results)
Next

function changenull(item)
'incase things are null
if item = vbempty or item = "" then
item = "NULL"
End Function
Avatar of bsharath

ASKER

I get this.

---------------------------
Windows Script Host
---------------------------
Script:      C:\Getechangestorsge.vbs
Line:      33
Char:      18
Error:      Invalid 'for' loop control variable
Code:      800A0410
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
oops

Const strtextfile = "C:\results.csv"

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
        "\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Exchange_Mailbox")

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.OpenTextFile(strtextfile,8,True)

Header =       "Associated content count" & vbtab & _
                  "Date discovered absent in directory service: " & vbtab & _
                  "Delete messages size extended " & vbtab & _
                  "Last logged-on user account " & vbtab & _
                  "Last logoff time" & vbtab & _
                  "Last logon time" & vbtab & _
                  "Legacy distinguished name" & vbtab & _
                  "Mailbox display name" & vbtab & _
                  "Mailbox GUID" & vbtab & _
                  "Server name" & vbtab & _
                  "Size" & vbtab & _
                  "Storage group name" & vbtab & _
                  "Storage limit information" & vbtab & _
                  "Store name" & vbtab & _
                  "Total items" & vbcrlf
oOutput.Write(header)
For Each objItem in colItems
results = results & changenull(objItem.AssocContentCount) & vbtab
results = results & changenull(objItem.DateDiscoveredAbsentInDS) & vbtab
results = results & changenull(objItem.DeletedMessageSizeExtended) & vbtab
results = results & changenull(objItem.LastLoggedOnUserAccount) & vbtab
results = results &      changenull(objItem.LastLogoffTime) & vbtab
results = results & changenull(objItem.LastLogonTime) & vbtab
results = results & changenull(objItem.LegacyDN) & vbtab
results = results & changenull(objItem.MailboxDisplayName) & vbtab
results = results & changenull(objItem.MailboxGUID) & vbtab
results = results & changenull(objItem.ServerName) & vbtab
results = results & changenull(objItem.Size) & vbtab
results = results & changenull(objItem.StorageGroupName) & vbtab
results = results & changenull(objItem.StorageLimitInfo) & vbtab
results = results & changenull(objItem.StoreName) & vbtab
results = results & changenull(objItem.TotalItems) & vbcrlf

oOutput.Write(Results)
Next

function changenull(item)
'incase things are null
if item = vbempty or item = "" then
item = "NULL"
End Function
strComputer = "."

if you're not running this on your exchange box, then

strComputer = "exchangeserver"    << where exchangeserver is tha name of your exchange server
You can right click on each mail store and export to a CSV file
weellio

After specifying the exchange name also i get this.

---------------------------
Windows Script Host
---------------------------
Script:      C:\Getechangestorsge.vbs
Line:      33
Char:      18
Error:      Invalid 'for' loop control variable
Code:      800A0410
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
Any help...
Any help...
mboppe:
You can right click on each mail store and export to a CSV file

did you try that?


Const strtextfile = "C:\results.csv"
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
        "\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Exchange_Mailbox")
if err.number <> 0 then
wscript.echo err.number & "  :  " & err.description & "  :  problem connection to" & strComputer
err.clear
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.OpenTextFile(strtextfile,8,True)

Header =       "Associated content count" & vbtab & _
                  "Date discovered absent in directory service: " & vbtab & _
                  "Delete messages size extended " & vbtab & _
                  "Last logged-on user account " & vbtab & _
                  "Last logoff time" & vbtab & _
                  "Last logon time" & vbtab & _
                  "Legacy distinguished name" & vbtab & _
                  "Mailbox display name" & vbtab & _
                  "Mailbox GUID" & vbtab & _
                  "Server name" & vbtab & _
                  "Size" & vbtab & _
                  "Storage group name" & vbtab & _
                  "Storage limit information" & vbtab & _
                  "Store name" & vbtab & _
                  "Total items" & vbcrlf
oOutput.Write(header)
For Each objItem in colItems
results = results & changenull(objItem.AssocContentCount) & vbtab
results = results & changenull(objItem.DateDiscoveredAbsentInDS) & vbtab
results = results & changenull(objItem.DeletedMessageSizeExtended) & vbtab
results = results & changenull(objItem.LastLoggedOnUserAccount) & vbtab
results = results & changenull(objItem.LastLogoffTime) & vbtab
results = results & changenull(objItem.LastLogonTime) & vbtab
results = results & changenull(objItem.LegacyDN) & vbtab
results = results & changenull(objItem.MailboxDisplayName) & vbtab
results = results & changenull(objItem.MailboxGUID) & vbtab
results = results & changenull(objItem.ServerName) & vbtab
results = results & changenull(objItem.Size) & vbtab
results = results & changenull(objItem.StorageGroupName) & vbtab
results = results & changenull(objItem.StorageLimitInfo) & vbtab
results = results & changenull(objItem.StoreName) & vbtab
results = results & changenull(objItem.TotalItems) & vbcrlf

oOutput.Write(Results)
Next

function changenull(item)
'incase things are null
if item = vbempty or item = "" then
item = "NULL"
End Function
back to top
I get this.

---------------------------
Windows Script Host
---------------------------
Script:      C:\Mailbox.vbs
Line:      56
Char:      5
Error:      Expected 'If'
Code:      800A03F4
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
Const strtextfile = "C:\results.csv"
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
        "\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Exchange_Mailbox")
if err.number <> 0 then
wscript.echo err.number & "  :  " & err.description & "  :  problem connection to" & strComputer
err.clear
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.OpenTextFile(strtextfile,8,True)

Header =       "Associated content count" & vbtab & _
                  "Date discovered absent in directory service: " & vbtab & _
                  "Delete messages size extended " & vbtab & _
                  "Last logged-on user account " & vbtab & _
                  "Last logoff time" & vbtab & _
                  "Last logon time" & vbtab & _
                  "Legacy distinguished name" & vbtab & _
                  "Mailbox display name" & vbtab & _
                  "Mailbox GUID" & vbtab & _
                  "Server name" & vbtab & _
                  "Size" & vbtab & _
                  "Storage group name" & vbtab & _
                  "Storage limit information" & vbtab & _
                  "Store name" & vbtab & _
                  "Total items" & vbcrlf
oOutput.Write(header)
For Each objItem in colItems
results = results & changenull(objItem.AssocContentCount) & vbtab
results = results & changenull(objItem.DateDiscoveredAbsentInDS) & vbtab
results = results & changenull(objItem.DeletedMessageSizeExtended) & vbtab
results = results & changenull(objItem.LastLoggedOnUserAccount) & vbtab
results = results & changenull(objItem.LastLogoffTime) & vbtab
results = results & changenull(objItem.LastLogonTime) & vbtab
results = results & changenull(objItem.LegacyDN) & vbtab
results = results & changenull(objItem.MailboxDisplayName) & vbtab
results = results & changenull(objItem.MailboxGUID) & vbtab
results = results & changenull(objItem.ServerName) & vbtab
results = results & changenull(objItem.Size) & vbtab
results = results & changenull(objItem.StorageGroupName) & vbtab
results = results & changenull(objItem.StorageLimitInfo) & vbtab
results = results & changenull(objItem.StoreName) & vbtab
results = results & changenull(objItem.TotalItems) & vbcrlf

oOutput.Write(Results)
Next

function changenull(item)
'incase things are null
if item = vbempty or item = "" then
item = "NULL"
end if
End Function
---------------------------
Windows Script Host
---------------------------
Script:      C:\Mailbox.vbs
Line:      57
Char:      13
Error:      Expected 'End'
Code:      800A03F6
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
Is there anything that i need to change
unfortunately i don't have access to run this against my own personal exchange server, so we will have to use trial and error,..

try this version



Const strtextfile = "C:\results.csv"
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
        "\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Exchange_Mailbox")
if err.number <> 0 then
wscript.echo err.number & "  :  " & err.description & "  :  problem connection to" & strComputer
err.clear
end if
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.OpenTextFile(strtextfile,8,True)

Header =       "Associated content count" & vbtab & _
                  "Date discovered absent in directory service: " & vbtab & _
                  "Delete messages size extended " & vbtab & _
                  "Last logged-on user account " & vbtab & _
                  "Last logoff time" & vbtab & _
                  "Last logon time" & vbtab & _
                  "Legacy distinguished name" & vbtab & _
                  "Mailbox display name" & vbtab & _
                  "Mailbox GUID" & vbtab & _
                  "Server name" & vbtab & _
                  "Size" & vbtab & _
                  "Storage group name" & vbtab & _
                  "Storage limit information" & vbtab & _
                  "Store name" & vbtab & _
                  "Total items" & vbcrlf
oOutput.Write(header)
For Each objItem in colItems
results = results & changenull(objItem.AssocContentCount) & vbtab
results = results & changenull(objItem.DateDiscoveredAbsentInDS) & vbtab
results = results & changenull(objItem.DeletedMessageSizeExtended) & vbtab
results = results & changenull(objItem.LastLoggedOnUserAccount) & vbtab
results = results & changenull(objItem.LastLogoffTime) & vbtab
results = results & changenull(objItem.LastLogonTime) & vbtab
results = results & changenull(objItem.LegacyDN) & vbtab
results = results & changenull(objItem.MailboxDisplayName) & vbtab
results = results & changenull(objItem.MailboxGUID) & vbtab
results = results & changenull(objItem.ServerName) & vbtab
results = results & changenull(objItem.Size) & vbtab
results = results & changenull(objItem.StorageGroupName) & vbtab
results = results & changenull(objItem.StorageLimitInfo) & vbtab
results = results & changenull(objItem.StoreName) & vbtab
results = results & changenull(objItem.TotalItems) & vbcrlf

oOutput.Write(Results)
Next

function changenull(item)
'incase things are null
if item = vbempty or item = "" then
item = "NULL"
end if
End Function
you get the scripts all the time,. you shoudl be able to look through them and notice irregularities,...

if you see an
IF statement, then it requires an END assuming that it is more than one line
I get this.

C:\>Exchange.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Exchange.vbs(59, 6) Microsoft VBScript compilation error: Syntax error
I remove the 59th line. I get this...

C:\>Exchange.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

424  :  Object required  :  problem connection to.
add back line 59 and try changing


strcomputer = "."
to
strcomputer = "exchangeserver"

where exchangeserver is your exchange servername
The reults come with these junk data.

15MB of file which has full of box symbols in it....
open it in excel
ASKER CERTIFIED SOLUTION
Avatar of William Elliott
William Elliott
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am trying to open i excel only...Ok i think right click is fine for now...
technically mboppe should have gotten the points,.
i merely ran in awild goose chase,.  :)
OOps sorry i did not see his comment.I though he answered for another queston of mine.

Sorry..

mboppe do you want me to open the Q to split points...
Thats okay Sharath.
Thanks a lot mboppe to be so kind...