Link to home
Start Free TrialLog in
Avatar of ABM Support
ABM Support

asked on

How do I retreive Exchange Store pathnames via scripting

I have a requirement to retrieve Exhange store pathnames from a server using a script. Once I can achieve this I then want to acquire the actual store size for reporting purposes. I can achieve this by hard-coding my store path but I need this to be done automatically. The script I have so far is as below....any ideas or advice please? (This script maybe rubbish....not attempted anything like this before!)

Thanks

Steve

set fso = createObject("scripting.fileSystemObject")
SET objRootDSE = CREATEOBJECT("LDAP://RootDSE")
configurationNamingContext = objRootDSE.GET("configurationNamingContext")
   
SET cn = CREATEOBJECT("ADODB.Connection")
SET cmd = CREATEOBJECT("ADODB.Command")
SET rs = CREATEOBJECT("ADODB.Recordset")

cn.Open "Provider=ADsDSOObject;"
       
query = "<LDAP://" & configurationNamingContext & ">;(objectCategory=msExchPrivateMDB);name,cn,distinguishedName;subtree"

cmd.ActiveConnection = cn
cmd.CommandText = query
SET rs = cmd.EXECUTE

WHILE rs.EOF <> TRUE AND rs.BOF <> TRUE
      ' wscript.echo rs.Fields("distinguishedname").Value

      ' CHANGE FILE LOCATIONS HERE
      strEDBPath = "E:\Program Files\Microsoft\Exchange Server\V14\Mailbox\Mailbox Database\Mailbox Database.edb"


      ' SCRIPT GETS FILE OBJECT HERE
      Set oEDB = fso.getFile(strEDBPath)


      ' SCRIPT SETS VARIABLES BASED UPON FILE SIZE HERE
      numEDBSize = oEDB.size

      ' SCRIPT ADDS THE TWO FILE SIZES HERE
      numTotalSize = numEDBSize

      ' FORMATTING SO IT OUTPUTS SIZE IN GB
      numTotalSize = (((numTotalSize /1024) /1024) /1024)

      'Delete the next line if you don't want this script to throw an error code
      if not err.number = 0 then numTotalSize = 99999999999999

      ' SCRIPT OUTPUTS THE SUM OF THE FILE SIZES
      wscript.echo numTotalSize

      rs.MoveNext
WEND
   
SET rs = NOTHING
SET cmd = NOTHING
SET cn = NOTHING
set oEDB = nothing
set fso = nothing
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada 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
Avatar of ABM Support
ABM Support

ASKER

Hi Will, thanks for the response.

I've tried the script which does work with a minor change to to the database name, however I also need to it to show the public database....any further advise?

Thanks

Steve