none
EWS to get size of all mailboxes on given mailbox server role

    Pertanyaan

  • Hi all,

    I am new to exchange environment and thus new to Exchange web services. I want to know size of all mailboxes on particular mailbox server in the domain. I know that we can get this data using exchange cmdlets. But I want to avoid powershell as it is resource hungry. Can we achieve this using EWS?

    Thanking you in anticipation!!!

    26 Oktober 2010 2:39

Jawaban

  • There is nothing in EWS that will return the size of all mailboxes on a server (eg something like what you could do with GetMailboxTable in mapi). You can only work at the mailbox level in EWS so the way to get the Mailbox-Size of one particular mailbox in EWS is to add the size of all the folders together eg

          Int32 TotalItemCount = 0;
          Int64 TotalSizeBytes = 0;
          ExtendedPropertyDefinition PR_Extended_Message_Size = new ExtendedPropertyDefinition(3592, MapiPropertyType.Long);
          PropertySet psPropertySet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Extended_Message_Size };
          FolderView fvFolderView = new FolderView(5000);
          fvFolderView.Traversal = FolderTraversal.Deep;
          fvFolderView.PropertySet = psPropertySet;
          FindFoldersResults ffResults = service.FindFolders(WellKnownFolderName.Root, fvFolderView);
          foreach (Folder ff in ffResults)
          {
            Object FolderSize = null;
            if (ff.TryGetProperty(PR_Extended_Message_Size, out FolderSize))
            {
              TotalSizeBytes = TotalSizeBytes + (Int64)FolderSize;
            }
            Object TotalItems = null;
            if (ff.TryGetProperty(FolderSchema.TotalCount,out TotalItems)) { 
              TotalItemCount = TotalItemCount + (Int32)TotalItems;
            }
          }
          Console.WriteLine("Mailbox Size : " + TotalSizeBytes);
          Console.WriteLine("Mailbox Item Count : " + TotalItemCount);
    

    To do this for all users on a server would require many calls and from a resource point of view the Exchange Management Shell is going to be less resource intensive and lot of faster for get the mailbox sizes.

    Cheers
    Glen

     

     

     

     

    • Ditandai sebagai Jawaban oleh eRohs 08 Nopember 2010 17:59
    27 Oktober 2010 6:02

Semua Balasan

  • There is nothing in EWS that will return the size of all mailboxes on a server (eg something like what you could do with GetMailboxTable in mapi). You can only work at the mailbox level in EWS so the way to get the Mailbox-Size of one particular mailbox in EWS is to add the size of all the folders together eg

          Int32 TotalItemCount = 0;
          Int64 TotalSizeBytes = 0;
          ExtendedPropertyDefinition PR_Extended_Message_Size = new ExtendedPropertyDefinition(3592, MapiPropertyType.Long);
          PropertySet psPropertySet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Extended_Message_Size };
          FolderView fvFolderView = new FolderView(5000);
          fvFolderView.Traversal = FolderTraversal.Deep;
          fvFolderView.PropertySet = psPropertySet;
          FindFoldersResults ffResults = service.FindFolders(WellKnownFolderName.Root, fvFolderView);
          foreach (Folder ff in ffResults)
          {
            Object FolderSize = null;
            if (ff.TryGetProperty(PR_Extended_Message_Size, out FolderSize))
            {
              TotalSizeBytes = TotalSizeBytes + (Int64)FolderSize;
            }
            Object TotalItems = null;
            if (ff.TryGetProperty(FolderSchema.TotalCount,out TotalItems)) { 
              TotalItemCount = TotalItemCount + (Int32)TotalItems;
            }
          }
          Console.WriteLine("Mailbox Size : " + TotalSizeBytes);
          Console.WriteLine("Mailbox Item Count : " + TotalItemCount);
    

    To do this for all users on a server would require many calls and from a resource point of view the Exchange Management Shell is going to be less resource intensive and lot of faster for get the mailbox sizes.

    Cheers
    Glen

     

     

     

     

    • Ditandai sebagai Jawaban oleh eRohs 08 Nopember 2010 17:59
    27 Oktober 2010 6:02
  • Hi Glen,

    would it be possible that you could provide the above code in VB 2008 ? I am only a VB beginner, and absolutely not used to C . I tried to use a code converter, but VB does not compile it.

    This is the VB code:

    1.  Imports System.Management
    2.  Imports System.Net
    3.  Imports System.Management.Automation
    4.  Imports Microsoft.Exchange.WebServices.Data
    5.  
    6.  Module Module1
    7.  
    8.      Sub Main()
    9.          Dim TotalItemCount As Int32 = 0
    10.        Dim TotalSizeBytes As Int64 = 0
    11.        Dim PR_Extended_Message_Size As New ExtendedPropertyDefinition(3592, MapiPropertyType.[Long])
    12.        Dim psPropertySet As New PropertySet(BasePropertySet.FirstClassProperties){PR_Extended_Message_Size}
    13.
    14.        Dim fvFolderView As New FolderView(5000)
    15.        fvFolderView.Traversal = FolderTraversal.Deep
    16.        fvFolderView.PropertySet = psPropertySet
    17.        Dim ffResults As FindFoldersResults = service.FindFolders(WellKnownFolderName.Root, fvFolderView)
    18.        For Each ff As Folder In ffResults
    19.            Dim FolderSize As [Object] = Nothing
    20.            If ff.TryGetProperty(PR_Extended_Message_Size, FolderSize) Then
    21.                TotalSizeBytes = TotalSizeBytes + DirectCast(FolderSize, Int64)
    22.            End If
    23.            Dim TotalItems As [Object] = Nothing
    24.            If ff.TryGetProperty(FolderSchema.TotalCount, TotalItems) Then
    25.                TotalItemCount = TotalItemCount + DirectCast(TotalItems, Int32)
    26.            End If
    27.        Next
    28.        Console.WriteLine("Mailbox Size : " & TotalSizeBytes)
    29.        Console.WriteLine("Mailbox Item Count : " & TotalItemCount)
    30.
    31.    End Sub
    32.
    33. End Module

    And the problem is line 12, VB can not handle the thing in curly brackets, seems a syntax error.

    Yould you (or someone else here) help me out with this?

    Many thanks for your help, much apreciated

    Regards
    Klaus

    04 Maret 2012 14:48
  • Try      

        Sub Main()
            Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
            service.Credentials = New System.Net.NetworkCredential("user@domain.com", "password")
            service.AutodiscoverUrl("user@domain.com", AddressOf UrlValidationCallback)
            Dim TotalItemCount As Int32 = 0
            Dim TotalSizeBytes As Int64 = 0
            Dim PR_Extended_Message_Size As New ExtendedPropertyDefinition(3592, MapiPropertyType.Long)
            Dim psPropertySet As New PropertySet(BasePropertySet.FirstClassProperties)
            psPropertySet.Add(PR_Extended_Message_Size)
            Dim fvFolderView As New FolderView(1000)
            fvFolderView.Traversal = FolderTraversal.Deep
            fvFolderView.PropertySet = psPropertySet
            Dim ffResults As FindFoldersResults
    
    
    
            Do
    
                ffResults = service.FindFolders(WellKnownFolderName.Root, fvFolderView)
                For Each ff As Folder In ffResults.Folders
                    Dim FolderSize As [Object] = Nothing
                    If ff.TryGetProperty(PR_Extended_Message_Size, FolderSize) Then
                        TotalSizeBytes = TotalSizeBytes + DirectCast(FolderSize, Int64)
                    End If
                    Dim TotalItems As [Object] = Nothing
                    If ff.TryGetProperty(FolderSchema.TotalCount, TotalItems) Then
                        TotalItemCount = TotalItemCount + DirectCast(TotalItems, Int32)
                    End If
                Next
                fvFolderView.Offset = ffResults.Folders.Count
    
            Loop While (ffResults.MoreAvailable = True)
            Console.WriteLine("Mailbox Size : " & TotalSizeBytes)
            Console.WriteLine("Mailbox Item Count : " & TotalItemCount)
    
        End Sub
        Function UrlValidationCallback(ByVal url As String) As Boolean
            ' Do proper validation instead of just returning True
            Return True
        End Function

    Cheers
    Glen
    05 Maret 2012 2:23