header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Get-mailbox and Get-MailboxFolderStatistics
Last Post 28 Jul 2011 11:06 AM by Marco Shaw. 17 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
John BrinesUser is Offline
New Member
New Member
Posts:12
Avatar

--
11 Sep 2008 06:55 AM

    Me again Guys

    I am using a script below to get the Deleted items information. What I want to be able to do is instead of using Identity from the Get-MailboxFolderStatistics I would like to use the DisplayName from get-mailbox

    get-mailbox | Get-MailboxFolderStatistics -FolderScope 'DeletedItems' | Select Identity, FolderPath, ItemsInFolder, FolderSize

    Thanks again

    John.

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    11 Sep 2008 09:10 AM
    Try this:

    foreach($mbx in Get-Mailbox){
    Get-MailboxFolderStatistics $mbx.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,FolderSize
    }



    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    John BrinesUser is Offline
    New Member
    New Member
    Posts:12
    Avatar

    --
    12 Sep 2008 04:17 AM
    Shay,

    Thanks yet again and I actually understand how it works. Now I am going to chance my arms :) Is it possible to have the FolderSize in KB or MB instead of just bytes?

    Also do you recommend any courses or books on Powrshell scripting?

    Thanks

    John.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    12 Sep 2008 04:33 AM
    Yes you can. If you pipe the folderSize member to get-member then you'll find a few methods for the job:

    ToGB()
    ToKB()
    ToMB()
    ToTB()

    To use them in your command, create a new calculated property and specify which one to use:

    foreach($mbx in Get-Mailbox){
    Get-MailboxFolderStatistics $mbx.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}
    }

    As for PowerShell books, here are some of my favorites:

    1. Windows PowerShell in Action, by Bruce Payette
    2. Windows PowerShell Cookbook, by Lee Holmes
    3. Windows PowerShell: TFM (3rd Edition), by Don Jones and Jefery Hicks
    4. Microsoft Windows PowerShell Step By Step, by Ed Wilson






    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    John BrinesUser is Offline
    New Member
    New Member
    Posts:12
    Avatar

    --
    12 Sep 2008 04:50 AM
    Cheers Shay.

    What is the best book from those for a Novice?

    John.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    12 Sep 2008 08:45 AM
    The first one!

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    NateCUser is Offline
    New Member
    New Member
    Posts:38
    Avatar

    --
    17 Oct 2008 07:09 AM

    Another great book I have found for the Exchange side of Powershell -

     

    Windows Powershell for Exchange Server 2007 SP1 by Cookey-Gam, Keane, Rosen, Runyon, and Stidley.

     

    Cheers.

    NewbieUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    17 Nov 2008 01:06 AM

    Hi guys,

    great thread!! This was excatly something i was also looking for. However, im trying to get the output of your statement:

    foreach($mbx in Get-Mailbox){
    Get-MailboxFolderStatistics $mbx.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}

    to a .csv file.

    But if i am using:

    foreach($mbx in Get-Mailbox){
    Get-MailboxFolderStatistics $mbx.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}
    } | export-csv c:\TEST.csv

    im getting Error: An empty pipe element is not permitted.

    So i was trying to use the foreach-object cmdlet instead of foreach statement:

    Get-Mailbox | foreach {Get-MailboxFolderStatistics $_.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$_.displayName}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}} | export-csv c:\TEST.csv

    But obviously “$_.displayName” is referencing  “get-mailboxfolderstatistics” instead of “get-mailbox”. What do I have to do???
     

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    17 Nov 2008 02:31 AM

    Assign the current mailbox inside the foreach cmdlet to $mbx:

    Get-Mailbox | foreach {
       $mbx = $_.DisplayName
       Get-MailboxFolderStatistics $_.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}
    } | export-csv c:\TEST.csv


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    NewbieUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    17 Nov 2008 03:56 AM

    Thank you very much for your input. 

    This was the essential advice. I didnt know that it is possible to do more than one command in the foreach loop.

    Though your statement was not totally correct, here is a final and working one, in case somebody else is also interested: 

    Get-Mailbox | foreach {
       $mbx = $_.DisplayName;
       Get-MailboxFolderStatistics $_.identity -FolderScope 'DeletedItems' | select @{n="DisplayName";e={$mbx}},FolderPath,ItemsInFolder,@{n="FolderSize(MB)";e={$_.folderSize.toMB()}}
    } | export-csv c:\TEST.csv

    Again, thank you very much for your help!!!!

    NateCUser is Offline
    New Member
    New Member
    Posts:38
    Avatar

    --
    22 May 2009 10:38 AM
    Is there any way to have a -folderscope that covers multiple folders, ie Inbox, Deleted Items, Sent Items, and Calendar.

    I have tried the folliowing without success:

    get-mailboxfolderstatistics -folderscope 'Inbox'; 'Deleted Items'; 'Sent Items'; 'Calendar'| ft FolderPath, ItemsInFolder, FolderandSubFolderSize

    I also tried it with a comma separated and without any separator. All with out success. My goal is to simply view the size of these four default folders on a mailbox.

    Any ideas on this?

    TIA

    Nate
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    22 May 2009 11:51 AM
    Nate;

    try this:
    $stats = 'Inbox', 'DeletedItems','SentItems','Calendar'|% {get-mailboxfolderstatistics -identity -FolderScope $_ |select FolderPath, ItemsInFolder, FolderandSubFolderSize}
    $stats
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    NateCUser is Offline
    New Member
    New Member
    Posts:38
    Avatar

    --
    22 May 2009 12:06 PM
    Good one Karl. In talking with some other folks we found another option. Here is one that also worked for me.


    param ($name)

    get-mailboxfolderstatistics $name |
    where-object {$_.foldersize -gt 1024000}|
    ft Name, ItemsInFolder,
    @{expression = {$_.foldersize.ToKB()}; label="Folder Size KB"}


    This option allowed me to find any folder, not necessarily the ones I started off looking for, with a size greater than 1MB (or whatever size you want).

    Being a newbie to all this I do need to learn about the following items in your solution. The use of "%" and "-FolderScope $_".

    Thanks for the help.

    Nate
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    22 May 2009 08:02 PM
    I fell victim to one of the classic blunders! The most famous is never get involved in a land war in Asia, but only slightly less well-known is this: never use an alias for cmdlets when posting example scripts :)

    % = foreach-object

    So, $stats = 'Inbox', 'DeletedItems','SentItems','Calendar'|foreach-object {get-mailboxfolderstatistics -identity -FolderScope $_ |select FolderPath, ItemsInFolder, FolderandSubFolderSize}

    In this case, we have 4 objects: 'Inbox', 'DeletedItems','SentItems','Calendar'

    We pipeline them to get-mailboxfolderstatistics, using $_ to refer to the current object on the pipeline.

    I probally over simplified, but this is how I understand it.

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    dmxopUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    18 Mar 2010 12:56 AM
    Hello,

    I have been making use of the script here and it works very well.  However, I have found that if deleted items has subfolders the MFS_Foldersize and MFS_itemsInFolderAndSubfolders are displaying as blank in the output csv file.

    Can anyone help?

    Thanks
    Mark
    happysportiUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    21 Apr 2010 10:27 PM
    I have a similar problem, but I dont know why it does not work. I would like to get the mailboxpermission from a list of mailboxes, and I want to export these Permissions to a csv-file. But I got the error message "An empty pipe element is not permitted."

    My part of the script which creates these error sounds :

    foreach ($G in import-csv $inputfile) {Get-MailboxPermission -identity $G.UPN | where-object {$_.IsInherited -like "False"} | Select-object Identity,User,Name,@{Name="AccessRights";Expression={[string]::join(";", ($_.AccessRights))}}}| export-csv -noType -path $Beforelog

    Does anybody have a idea what I made wrong ? Or what I could do to prevent this error ?

    Best Regards
    DarioUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    28 Jul 2011 09:58 AM
    Greetings,

    I am new to PowerShell scripting and I am looking to find a particular user(s) folder structure in their Exchange mailbox. I have been asked to gather terminated users folder structure so management can review them for future use or reference. Does anyone know the proper syntax to obtain the folder structure?

    Thanks in advance...

    Dario
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    28 Jul 2011 11:06 AM
    Please start a new thread.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer