locked
Get-MailboxFolderStatistics and exporting FolderAndSubfolderSize RRS feed

  • Question

  • Exchange 2010 SP2

    We are putting together a script to be run once a week to monitor usage of select mailboxes and their use of managed folders (in this example, the managed foldername is 2Year). We just want to get aggregate size and item counts of this managed folders and any subfolders it may contain. I put together the script below, and it runs without error. However, the last attribute - FolderAndSubfolderSize - is consistently blank. I do get a value when I remove the "Value.toMB()" at the end of it. I have also tried changing it to just "toMB()", but that still returns no value. Is there something off in my syntax?

    Is there a better way to get this information? How can I get the value for FolderAndSubfolderSize in MB like I do with the TotalItemSize value using the Get-MailboxStatistics cmdlet?


    $mbx = (Get-Group -identity "groupname").members

    $mbx | select-object displayname,@{label="MailboxSize(MB)";expression={(Get-MailboxStatistics $_).TotalItemSize.Value.ToMB()}},@{label="TotalItems_2Year";expression={(Get-MailboxFolderStatistics $_ -folderscope managedcustomfolder | where {$($_.Name) -eq "2Year"}).ItemsInFolderAndSubfolders}},@{label="TotalSize_2Year";expression={(Get-MailboxFolderStatistics $_ -folderscope managedcustomfolder | where {$($_.Name) -eq "2Year"}).FolderAndSubfolderSize.Value.toMB()}} | export-csv -notypeinformation -path ".\report.csv"

    Wednesday, October 31, 2012 5:25 PM

Answers

  • I haven't played with Managed Folders, and don't have time to learn today, so I don't know why they are behaving differently.  Perhaps you could use a workaround, like

    Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize.Split(" ")[0]

    or some other type conversion.


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    • Marked as answer by davrion Thursday, November 1, 2012 8:13 PM
    Thursday, November 1, 2012 4:55 PM

All replies

  • On Wed, 31 Oct 2012 17:25:59 +0000, davrion wrote:
     
    >
    >
    >Exchange 2010 SP2
    >
    >We are putting together a script to be run once a week to monitor usage of select mailboxes and their use of managed folders (in this example, the managed foldername is 2Year). We just want to get aggregate size and item counts of this managed folders and any subfolders it may contain. I put together the script below, and it runs without error. However, the last attribute - FolderAndSubfolderSize - is consistently blank. I do get a value when I remove the "Value.toMB()" at the end of it. I have also tried changing it to just "toMB()", but that still returns no value. Is there something off in my syntax?
    >
    >Is there a better way to get this information? How can I get the value for FolderAndSubfolderSize in MB like I do with the TotalItemSize value using the Get-MailboxStatistics cmdlet?
    >
    >$mbx = (Get-Group -identity "groupname").members
    >
    >$mbx | select-object displayname,@{label="MailboxSize(MB)";expression={(Get-MailboxStatistics $_).TotalItemSize.Value.ToMB()}},@{label="TotalItems_2Year";expression={(Get-MailboxFolderStatistics $_ -folderscope managedcustomfolder | where {$($_.Name) -eq "2Year"}).ItemsInFolderAndSubfolders}},@{label="TotalSize_2Year";expression={(Get-MailboxFolderStatistics $_ -folderscope managedcustomfolder | where {$($_.Name) -eq "2Year"}).FolderAndSubfolderSize.Value.toMB()}} | export-csv -notypeinformation -path ".\report.csv"
     
     
    (Get-MailboxFolderStatistics $_ -folderscope
    managedcustomfolder).FolderAndSubfolderSize|gm
     
    There's no "Value" property. Just use ".toMB()".
     
    I tried it on a parent folder with several children and got the right
    answer:
     
    (Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq
    'aliases'}).FolderAndSubfolderSize.toMB()
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Wednesday, October 31, 2012 7:02 PM
  • "(Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq 'aliases'}).FolderAndSubfolderSize.toMB()"

    When I run the command above (substituting a mailbox name and folder name), I get an error reported below:

              Method invocation failed because [System.String] doesn't contain a method named 'toMB'.

    I ran the get-method command, and the output does not show any Value option (like TotalItemSize does for Get-MailboxStatistics) and there aren't any toMB or toGB or anything similar listed.  Could this be a rollup change? We're on plain SP2 with no rollups (we're on a maintenance freeze currently).



    • Edited by davrion Thursday, November 1, 2012 1:19 PM
    Thursday, November 1, 2012 1:18 PM
  • Here is what the get-member returned for FolderAndSubfolderSize:

    Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize | Get-Member

    TypeName: System.String

    "TypeName","Name","MemberType","Definition"
    "System.String","Clone","Method","System.Object Clone()"
    "System.String","CompareTo","Method","int CompareTo(System.Object value), int CompareTo(string strB)"
    "System.String","Contains","Method","bool Contains(string value)"
    "System.String","CopyTo","Method","System.Void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)"
    "System.String","EndsWith","Method","bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType), bool EndsWith(string value, bool ignoreCase, System.Globalization.CultureInfo culture)"
    "System.String","Equals","Method","bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.StringComparison comparisonType)"
    "System.String","GetEnumerator","Method","System.CharEnumerator GetEnumerator()"
    "System.String","GetHashCode","Method","int GetHashCode()"
    "System.String","GetType","Method","type GetType()"
    "System.String","GetTypeCode","Method","System.TypeCode GetTypeCode()"
    "System.String","IndexOf","Method","int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(char value, int startIndex, int count), int IndexOf(string value), int IndexOf(string value, int startIndex), int IndexOf(string value, int startIndex, int count), int IndexOf(string value, System.StringComparison comparisonType), int IndexOf(string value, int startIndex, System.StringComparison comparisonType), int IndexOf(string value, int startIndex, int count, System.StringComparison comparisonType)"
    "System.String","IndexOfAny","Method","int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int IndexOfAny(char[] anyOf, int startIndex, int count)"
    "System.String","Insert","Method","string Insert(int startIndex, string value)"
    "System.String","IsNormalized","Method","bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizationForm)"
    "System.String","LastIndexOf","Method","int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int LastIndexOf(char value, int startIndex, int count), int LastIndexOf(string value), int LastIndexOf(string value, int startIndex), int LastIndexOf(string value, int startIndex, int count), int LastIndexOf(string value, System.StringComparison comparisonType), int LastIndexOf(string value, int startIndex, System.StringComparison comparisonType), int LastIndexOf(string value, int startIndex, int count, System.StringComparison comparisonType)"
    "System.String","LastIndexOfAny","Method","int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex), int LastIndexOfAny(char[] anyOf, int startIndex, int count)"
    "System.String","Normalize","Method","string Normalize(), string Normalize(System.Text.NormalizationForm normalizationForm)"
    "System.String","PadLeft","Method","string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)"
    "System.String","PadRight","Method","string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)"
    "System.String","Remove","Method","string Remove(int startIndex, int count), string Remove(int startIndex)"
    "System.String","Replace","Method","string Replace(char oldChar, char newChar), string Replace(string oldValue, string newValue)"
    "System.String","Split","Method","string[] Split(Params char[] separator), string[] Split(char[] separator, int count), string[] Split(char[] separator, System.StringSplitOptions options), string[] Split(char[] separator, int count, System.StringSplitOptions options), string[] Split(string[] separator, System.StringSplitOptions options), string[] Split(string[] separator, int count, System.StringSplitOptions options)"
    "System.String","StartsWith","Method","bool StartsWith(string value), bool StartsWith(string value, System.StringComparison comparisonType), bool StartsWith(string value, bool ignoreCase, System.Globalization.CultureInfo culture)"
    "System.String","Substring","Method","string Substring(int startIndex), string Substring(int startIndex, int length)"
    "System.String","ToCharArray","Method","char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)"
    "System.String","ToLower","Method","string ToLower(), string ToLower(System.Globalization.CultureInfo culture)"
    "System.String","ToLowerInvariant","Method","string ToLowerInvariant()"
    "System.String","ToString","Method","string ToString(), string ToString(System.IFormatProvider provider)"
    "System.String","ToUpper","Method","string ToUpper(), string ToUpper(System.Globalization.CultureInfo culture)"
    "System.String","ToUpperInvariant","Method","string ToUpperInvariant()"
    "System.String","Trim","Method","string Trim(Params char[] trimChars), string Trim()"
    "System.String","TrimEnd","Method","string TrimEnd(Params char[] trimChars)"
    "System.String","TrimStart","Method","string TrimStart(Params char[] trimChars)"
    "System.String","Chars","ParameterizedProperty","char Chars(int index) {get;}"
    "System.String","Length","Property","System.Int32 Length {get;}"



    • Edited by davrion Thursday, November 1, 2012 2:19 PM
    Thursday, November 1, 2012 1:35 PM
  • I haven't used get-method, and can't find any reference to it.  But what do you get for

    "(Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize

    and

    "(Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize | Get-Member


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Thursday, November 1, 2012 2:08 PM
  • Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize   - I get the following result:

    38.62 MB (40,493,317 bytes)

    Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize | Get-Member

    I posted the results a few minutes earlier in an above post which I mislabelled and have now corrected it.

    Thursday, November 1, 2012 2:19 PM
  • Ah, right.  I got a much shorter list than yours, which does include ToMB, ToGB, etc., so I thought you may have been using a different command.  I've absolutely no idea why they should be different, though.  Mine doesn't actually have the quote marks like yours does, either.  Are you perhaps using a newer version of powershell?

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Thursday, November 1, 2012 3:22 PM
  • I exported the gm results to a CSV to make the copy/paste easier so nothing was cut off, so that's why the quotes were there.

    This is what I get from $host.version:

    Major  Minor  Build  Revision
    -----  -----  -----  --------
    2      0      -1     -1


    Also, we have no post-SP2 rollups for Exchange installed (change freeze), so I don't know if this behavior was changed in one of the rollups or not.
    • Edited by davrion Thursday, November 1, 2012 3:42 PM
    Thursday, November 1, 2012 3:35 PM
  • PS version is as expected.  I'd be surprised if the rollups made such a vast difference to the output, but I suppose it's certainly possible.

    What happens if you try something like .FolderSize instead of .FolderAndSubfolderSize ?


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Thursday, November 1, 2012 3:46 PM
  • FolderSize looks the same as FolderAndSubfolderSize in terms of behavior
    Thursday, November 1, 2012 4:01 PM
  • Seems strange. How about if you try it with a different folder, like your Inbox?


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Thursday, November 1, 2012 4:16 PM
  • Inbox folder does have the toMB et al.

    The main difference I can see if that the folders I am reporting on are managed folders (set up using the Set-Mailbox -ManagedFolderMailboxPolicy cmdlet). This is the functionality that was removed from the 2010 console.

    Thursday, November 1, 2012 4:30 PM
  • I haven't played with Managed Folders, and don't have time to learn today, so I don't know why they are behaving differently.  Perhaps you could use a workaround, like

    Get-MailboxFolderStatistics -Identity "mbxname" | where {$_.name -eq '2Year'}).FolderAndSubfolderSize.Split(" ")[0]

    or some other type conversion.


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    • Marked as answer by davrion Thursday, November 1, 2012 8:13 PM
    Thursday, November 1, 2012 4:55 PM
  • Yes, that addition at the end gets me exactly what I needed.

    Thanks!

    Thursday, November 1, 2012 8:13 PM