?
Solved

Powershell - Get-Mailbox + Get-MailboxStatistics

Posted on 2014-08-11
6
Medium Priority
?
3,959 Views
Last Modified: 2014-08-12
Hi experts,

I can't figure out where the mistake is in this cmdlet:

Get-mailbox | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox" } | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"} -Autosize

I'm trying to pipline Get-MailboxStatistics thru get-mailbox cmdlets. If i use the above per user it works fine. But once i use it with filter or Where-Object i do not get results for ItemCount.

See output below:
[PS] C:\>Get-mailbox | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox" } | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"} -Autosize

DisplayName                 ItemCount
-----------                 ---------
Mailbox1
Mailbox2
Mailbox3

Your advice much appreciated.
0
Comment
Question by:Excel
  • 3
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Simon Butler (Sembee)
ID: 40253715
Use get-recipient at the start instead of get-mailbox

Simon.
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40253776
if you add -ShowError
 Get-mailbox | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox" } | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"} -showerror

Open in new window

you will see the error message.
Failed to evaluate expression " ((Get-MailboxStatistics $_.DisplayName).ItemCount)".
    + CategoryInfo          : InvalidArgument: (Fimail_Admin:PSObject) [], CmdletInvocationException
    + FullyQualifiedErrorId : mshExpressionError


and it will work like below

Get-mailbox -Filter {RecipientTypeDetails -eq "SharedMailbox"} | Get-MailboxStatistics | select DisplayName,ItemCount

Open in new window

Note:
and I am not 100% sure why you have that error but which I believe when it passes the value via pipeline, it is already going to the next value and it is not fast enough to show up the info of getting get-mailboxstatistics. so the displayname returned and however the statistics isn't available at that moment yet. (that's why it goes blank)
0
 

Author Comment

by:Excel
ID: 40255112
Simon, thanks for a suggestion. Still no output with Get-Recipient cmdlet.

[PS] C:\>Get-Recipient | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox" } | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"}

DisplayName                                                 ItemCount
-----------                                                 ---------
Mailbox1
Mailbox2
Mailbox3
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

Author Comment

by:Excel
ID: 40255137
Lustin, if i use -ShowError i don't seem to get any error displayed.

Re -Filter switch, I've tried that prior too. No luck but the result is a bit different. It returns ItemCount for the last line entry. See below.

[PS] C:\>Get-mailbox -filter {RecipientTypeDetails -eq "SharedMailbox"} | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"}

DisplayName                                                 ItemCount
-----------                                                 ---------
Mailbox1
Mailbox2
Mailbox3                                                 25

Your suggested cmdlet with filter differs from what I'm working on. It won't return any results from Get-Mailbox parameters what are not part of Get-MailboxStatistics (eg ProhibitSendQuota or IssueWarningQuota)

Example:
it works if:
Get-mailbox -Filter {RecipientTypeDetails -eq "SharedMailbox"} | Get-MailboxStatistics | select DisplayName,ItemCount
                                       
it does not work if:
Get-mailbox -Filter {RecipientTypeDetails -eq "SharedMailbox"} | Get-MailboxStatistics | select DisplayName,ItemCount,IssueWarningQuota
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 2000 total points
ID: 40255785
first this will not work since "IssueWarningQuota" is not a property of "Get-MailboxStatistic"
Get-mailbox -Filter {RecipientTypeDetails -eq "SharedMailbox"} | Get-MailboxStatistics | select DisplayName,ItemCount,IssueWarningQuota

Second
Get-mailbox -filter {RecipientTypeDetails -eq "SharedMailbox"} | ft DisplayName,@{e={ ((Get-MailboxStatistics $_.DisplayName).ItemCount)};Label="ItemCount"}

Filtering before pipeline is always faster since it doesn't process all the result before where-object
and as I mentioned before when it does the pipeline it might not be fast enough to do so.

however once you turns the search result to variable it will store in to your console memory
so then I will work as below

$Mailboxes = Get-mailbox -Filter {RecipientTypeDetails -eq "SharedMailbox"}
Foreach ($Mailbox in $Mailboxes)
{
Get-MailboxStatistics $Mailbox | select DisplayName,ItemCount,@{N="Quota";E={$Mailbox.IssueWarningQuota}}
}

Open in new window

0
 

Author Closing Comment

by:Excel
ID: 40255908
Thanks Justin, it's exactly what i was looking for.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
If you have come across a situation where you need to find some EDB mailbox recovery techniques, then here you will find the same. In this article, we will take you through three techniques using which you will be able to perform EDB recovery. You …
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question