Announcement

Collapse
No announcement yet.

Exchange Store Size VBS Script Query

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exchange Store Size VBS Script Query

    Hi,

    Sadly my scripting skills fail me significantly at this level. Daniel posted this on the main site a while ago which I'm sure works really well:
    http://www.petri.com/reporting_stora...n_exchange.htm
    however I don't have access, in my org, to all of the exchange servers so I need to modify it to pull just the exchange servers in my domain. I find if I pull the entire forest it tries the first server and fails with a:
    exch-store-space.wsf(70, 5) Microsoft VBScript runtime error: File not found
    error message (i've checked and I believe all files exist correctly so figured this was an access error?). The VB below is part of the systeminfo.vbs script.

    Code:
    ' This file contains the routines to find out about servers, storage groups, and
    ' stores in an Exchange organization. Each individual routine is preceeded
    ' by individual documentation.
    
    ' all lists are semi-colon separated
    
    ' a list of all the servers in the organization
    ' and a parallel list containing their distinguished names
    Dim strServerList, strServerListDN
    
    ' a list of all OAL's in the organization
    ' and a parallel list containing their adminText attribute
    Dim strOALList, strAdminList
    
    ' a list of all administrative groups in the org
    ' and a parallel list containing their distinguished names
    Dim strAGroupList, strAGroupListDN
    
    ' a list of all servers in an admin group
    Dim strServerAGList
    
    ' a list of all storage groups on a server
    ' and a parallel list containing their distinguished names
    Dim strServerSG, strServerSGDN
    
    ' a list of all the stores in a storage group (by distinguished name) 
    ' and a parallel list of their types (public or private)
    Dim strStoreDN, strStoreType
    '
    ' GetAllServers
    ' Purpose:
    '  Get a list of all servers in the Exchange organization, and
    '  prepare two semi-colon separated lists - one of the short
    '  server name and one of the server distinguished name.
    '
    ' Inputs:
    '  None
    '
    ' Outputs:
    '  Sets the value of the global variables strServerList and
    '  strServerListDN
    '
    ' Requires:
    '  strOrgDN from GetOrganizationInformation
    '
    Sub GetAllServers
     Dim strQuery
    
     ' Get the list of all servers within the organization
     strQuery = "<LDAP://" & "CN=Administrative Groups," & strOrgDN & ">;" & _
      "(objectCategory=msExchExchangeServer);" & _
      "name,cn,distinguishedName;" & _
      "subtree"
    
     strServerList   = ""
     strServerListDN = ""
    
     Call DoLDAPQuery (strQuery, Rs)
    
     p "All Exchange Servers in forest " & strDomainNC
     While Not Rs.EOF
      ' output the current server found
      dp "Server CN: " & Rs.Fields ("cn")
      e  vbTab & "Server Name: " & Rs.Fields ("name")
      dp "Server DN: " & Rs.Fields ("distinguishedName")
    
      strServerList   = strServerList   & ";" & Rs.Fields ("name")
      strServerListDN = strServerListDN & ";" & Rs.Fields ("distinguishedName")
    
      Rs.MoveNext
     Wend
    
     strServerList = Mid (strServerList, 2)
     strServerListDN = Mid (strServerListDN, 2)
    
     Call FinishLDAPQuery (Rs)
    
     ' Report our results
     e " "
     dp "strServerList = " & strServerList
     dp "strServerListDN = " & strServerListDN
     dp " "
    End Sub
    '
    ' GetAllOfflineAddressLists
    ' Purpose:
    '  Prepare two semi-colon separated lists, one containing the
    '  offline address lists present in the Exchange organization,
    '  and the other containing the adminDescription field for the
    '  OAL (used to store business logic information).
    '
    ' Inputs:
    '  None
    '
    ' Outputs:
    '  Set the value of the global variables strOALList and
    '  strAdminList.
    '
    ' Requires:
    '  strOrgDN from GetOrganizationInformation
    '
    Sub GetAllOfflineAddressLists
     Dim strQuery
     Dim str
    
     ' Get the list of all offline address lists within the organization
     strQuery = "<LDAP://" & "CN=Offline Address Lists,CN=Address Lists Container," & strOrgDN & ">;" & _
      "(objectCategory=msExchOAB);" & _
      "name,adminDescription;" & _
      "onelevel"
    
     strOALList = ""
     strAdminList = ""
    
     Call DoLDAPQuery (strQuery, Rs)
    
     dp "All OALs in DN " & "CN=Offline Address Lists,CN=Address Lists Container," & strOrgDN
     While Not Rs.EOF
      str = Rs.Fields ("adminDescription")
      If IsNull (str) or (Len (str) = 0) Then
       str = "<null>"
      End If
    
      strOALList   = strOALList   & ";" & Rs.Fields ("name")
      strAdminList = strAdminList & ";" & str
    
      Rs.MoveNext
     Wend
    
     strOALList = Mid (strOALList, 2)
     strAdminList = Mid (strAdminList, 2)
    
     Call FinishLDAPQuery (Rs)
    
     ' Report our results
     dp "strOALList = " & strOALList
     dp "strAdminList = " & strAdminList
    End Sub
    '
    ' GetAdministrativeGroupInformation
    ' Purpose:
    '  Prepare a semi-colon separated list containing all administrative
    '  groups in the Exchange organization.
    '
    ' Inputs:
    '  None
    '
    ' Outputs:
    '  Set the value of the global variable strAGroupList
    '
    ' Requires:
    '  strOrgDN from GetOrganizationInformation
    '
    Sub GetAdministrativeGroupInformation
     Dim strQuery
    
     ' Get the list of all Administrative Groups within the organization
     strQuery = "<LDAP://CN=Administrative Groups," & strOrgDN & ">;" & _
      "(objectCategory=msExchAdminGroup);" & _
      "name,cn,distinguishedName;" & _
      "onelevel"
    
     strAGroupList = ""
     strAGroupListDN = ""
    
     Call DoLDAPQuery (strQuery, Rs)
    
     While Not Rs.EOF
      ' output the current administrative group found
      dp "Admin Group CN: " & Rs.Fields ("cn")
      dp "Administrative Group Name: " & Rs.Fields ("name")
      dp "Admin Group DN: " & Rs.Fields ("distinguishedName")
    
      strAGroupList = strAGroupList & ";" & Rs.Fields ("name")
      strAGroupListDN = strAGroupListDN  & ";" & Rs.Fields ("distinguishedName")
    
      Rs.MoveNext
     Wend
    
     strAGroupList = Mid (strAGroupList, 2)
     strAGroupListDN = Mid (strAGroupListDN, 2)
    
     Call FinishLDAPQuery (Rs)
    
     ' Report our results
     dp "strAGroupList = " & strAGroupList
    End Sub
    '
    ' GetServersForAdministrativeGroup
    ' Purpose:
    '  Prepare a semi-colon separated list of all servers in the
    '  Exchange organization. This shows an alternate method of
    '  obtaining the GetAllServers list, doing a "onelevel" search
    '  instead of a "subtree" search. However, since the query uses
    '  an indexed attribute, objectCategory, the added complexity
    '  does not buy any performance benefit.
    '
    ' Inputs:
    '  None
    '
    ' Outputs:
    '  Set the value of the global variable strServerAGList
    '
    ' Requires:
    '  strOrgDN from GetOrganizationInformation
    '
    Sub GetServersForAdministrativeGroup
     ' Get the list of servers for each administrative group
     ' (this is provided just in case you are interested)
     Dim strQuery, strServerAGList
     Dim arr
     Dim i
    
     arr = Split (strAGroupList, ";")
    
     strServerAGList = ""
    
     For i = LBound (arr) To UBound (arr)
      e "Exchange Servers for Administrative Group: " & arr (i)
      strQuery = "<LDAP://" & _
       "CN=Servers,CN=" & arr (i) & ",CN=Administrative Groups," & strOrgDN & ">;" & _
       "(objectCategory=msExchExchangeServer);" & _
       "name,cn,distinguishedName;" & _
       "onelevel"
    
      Call DoLDAPQuery (strQuery, Rs)
    
      While Not Rs.EOF
       ' output the current server found
       dp "Server CN: " & Rs.Fields ("cn")
       e "Server Name: " & Rs.Fields ("name")
       dp "Server DN: " & Rs.Fields ("distinguishedName")
    
       strServerAGList = strServerAGList & ";" & Rs.Fields ("name")
    
       Rs.MoveNext
      Wend
    
      strServerAGList = Mid (strServerAGList, 2)
    
      Call FinishLDAPQuery (Rs)
    
      dp "Exchange server list for AG " & arr (i) & ": " & strServerAGList
     Next
    End Sub
    '
    ' GetStoresForStorageGroup
    ' Purpose:
    '  Prepare a semi-colon separated list of all the message stores
    '  in a given storage group. A parallel list containing the type
    '  of the storage group is also prepared. This routine uses ADSI
    '  enumeration to obtain the list.
    '
    ' Inputs:
    '  strStorageGroup - contains the distinguished name of the storage
    '  group to be examined.
    '
    ' Outputs:
    '  Set the value of the global variables strStoreDN and strStoreType
    '
    ' Requires:
    '  None
    '
    Sub GetStoresForStorageGroup (strStorageGroup)
     Dim objSG, objStore
     Dim strOC, strType
    
     strStoreDN   = ""
     strStoreType = ""
    
     Set objSG = GetObject ("LDAP://" & strStorageGroup)
    
     For Each objStore in objSG
      strOC = objStore.Get ("objectCategory")
      ' turn objectCategory into objectClass
      strType = Left (strOC, Instr (strOC, ",") - 1)
      strType = Replace (Mid (strType, 4), "-", "")
    
      dp vbTab & "store: " & objStore.Name & _
       " " & strType
    
      strStoreDN   = strStoreDN   & ";" & objStore.Get ("distinguishedName")
      strStoreType = strStoreType & ";" & strType
     Next
    
     strStoreDN   = Mid (strStoreDN, 2)
     strStoreType = Mid (strStoreType, 2)
    
     ' Report results
     dp "store DN's: " & strStoreDN
     dp "store Types: " & strStoreType
    End Sub
    '
    SNIP
    Edit by Dumber, URL tags added around URL.
    Last edited by Dumber; 21st April 2009, 12:09.
    cheers
    Andy

    Please read this before you post:


    Quis custodiet ipsos custodes?

  • #2
    Re: Exchange Store Size VBS Script Query

    Originally posted by AndyJG247 View Post
    I find if I pull the entire forest it tries the first server and fails with a:
    exch-store-space.wsf(70, 5) Microsoft VBScript runtime error: File not found
    Gosh, that's hard code to debug with all the one letter sub calls. Anyway, the error is likely triggered by this statement:

    Set objFile = objFSO.GetFile (strFile)

    strFile is constructed like this:

    strFile = "\\" & strServer & "\" & Left (s, 1) & "$" & Mid (s, 3)

    The obvious way would be double-checking what objFSO is trying to open. So just enter a print statement to display the file name. Maybe:
    e strFile
    would do the trick, if I'm not mistaken about the e sub. Should I be, use:
    wscript.echo "BUG HERE: " & strFile

    I guess a work-around can be build by using Filesysteminfo.FileExists method to test wether the file actually exists.

    -vP

    Comment


    • #3
      Re: Exchange Store Size VBS Script Query

      Hi vonPryz, thanks for the info. Not sure what that meant though, do you suggest putting that into the script?
      cheers
      Andy

      Please read this before you post:


      Quis custodiet ipsos custodes?

      Comment


      • #4
        Re: Exchange Store Size VBS Script Query

        I was looking at ScriptingAnswers.com and the "Exchange Mailbox Store Report" script. I thought that this script would be much easier....you could modify it to only display the path of the store's DB, and then just simply get the file size of the DB like so:

        Code:
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.GetFile("\\" & strServer & "\" & strData)
           wscript.echo objFile.Size & "bytes"
        EDIT*** Try my edit below...I think this will be much more simpler for what you want...

        Code:
        strTitle="Mailbox Storage DB Report"
        strServer=InputBox("What is the name of the Exchange Server?",strTitle)
        
        SGReport strServer
        WScript.Quit
        
        Sub SGReport(strServer)
        Dim iServer
        Dim iSGs
        Dim iMBS
        
        Set iServer=CreateObject("CDOEXM.ExchangeServer")
        Set iSGs=CreateObject("CDOEXM.StorageGroup")
        Set iMBs=CreateObject("CDOEXM.MailboxStoreDB")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        iServer.DataSource.Open strServer
        
        arrSGs=iServer.StorageGroups
        
        For i=0 To UBound(arrSGs)
        	strSGUrl=arrSGs(i)
        	'WScript.Echo strSGUrl
        	iSGs.DataSource.Open "LDAP://" & iServer.DirectoryServer & "/" & strSGUrl
        	arrMBStores=iSGs.MailboxStoreDBs
        	For j=0 To UBound(arrMBStores)
        		iMBS.DataSource.open "LDAP://" & arrMBStores(j)	
                        ' make the path of the exchange store readable for the network
                        ' wow I don't know why I was making this so complicated....
        		strLocalPath = iMBS.DBPath
        		strNetPath = Replace(strLocalPath, ":", "$")
        	Next
        	
        Next
        
        Set objFile = objFSO.GetFile("\\" & strServer & "\" & strNetPath)
                ' convert size to MB
        	Size = Round(objFile.Size / 1048576, 1)
        WScript.Echo Size & " MB"
        
        End sub
        Last edited by ekrengel; 22nd April 2009, 19:39. Reason: shortened replace function

        Comment


        • #5
          Re: Exchange Store Size VBS Script Query

          Originally posted by AndyJG247 View Post
          do you suggest putting that into the script?
          Sure. I'll explain in more a detail. What you need to do is pretty straight-forward. First off, take a backup of the original script. Then use Notepad or some other editor (I fancy VIM, SciTe and Notepad++ will do too) and navigate to row 70, where the file will look like this (I added the line numbers for improved readability, do not type them into the file):
          Code:
          68:   strFile = "\\" & strServer & "\" & _
          69:    Left (s, 1) & "$" & Mid (s, 3)
          70:   Set objFile = objFSO.GetFile (strFile)
          71:   e Space (6) & "Size: " & _
          72:    FormatNumber (objFile.Size / (1024 * 1024), 0) & _
          73:    " megabytes"
          Insert an echo statement to row 70, so the file will look like this:
          Code:
          68:   strFile = "\\" & strServer & "\" & _
          69:    Left (s, 1) & "$" & Mid (s, 3)
          70:   wscript.echo "Now reading " & strFile
          71:   Set objFile = objFSO.GetFile (strFile)
          72:   e Space (6) & "Size: " & _
          73:    FormatNumber (objFile.Size / (1024 * 1024), 0) & _
          74:    " megabytes"
          Save the file and run the script. What the wscript.echo statement does is that it will print the names of the files objFSO is trying to open. If the filenames are OK, double check that access is OK. Maybe there is a typo on some path or the like. Use copy-paste. That way you won't accidentally fix a typo in the path.

          -vP

          Comment


          • #6
            Re: Exchange Store Size VBS Script Query

            Thanks guys, I haven't forgotten this.
            Will try in a bit
            cheers
            Andy

            Please read this before you post:


            Quis custodiet ipsos custodes?

            Comment

            Working...
            X