Solved

[Powershell] Mailbox.Count Issue

Posted on 2016-10-25
4
28 Views
Last Modified: 2016-11-15
I can't figure this out - it's drilling a hole through me.

OK so I run ->  
Get-Mailbox -ResultSize Unlimited | Select Alias,PrimarySmtpAddress

Open in new window

It works I get all the mailboxes.
I run
Get-Mailbox -Identity "sample" | Select Alias,PrimarySmtpAddress

Open in new window

It finds the user.
but if I run the code (pasted) below when It's supposed to output the number of mailboxes it shows 0 even though the answer is one.

I don't get how it can't count the mailbox and can count them all.

I'm running on this Exchange 2010 EWS powershell


Examplenumber2.png
Screenshot_5.png
0
Comment
Question by:Network Zero
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:Todd Nelson
Todd Nelson earned 100 total points (awarded by participants)
ID: 41859733
It will not output a count when you explicitly specify a mailbox.  And, unfortunately, it will not provide output if only one mailbox that meets the criteria either; as far as I have ever seen.

If you want it to output a count of mailboxes based on the criteria you wrote, it cannot be explicitly stated (i.e. 'Get-Mailbox -Identity "sample"' ), and there must be at least 2 mailboxes that meet the criteria.

For example, if you have 2 mailboxes that have the word 'sample' in them, it might be better to write that portion of the script like this...

$Mailbox = Get-Mailbox | Where-Object  {$_.Name -like "Sampl*" }

Open in new window

0
 
LVL 83

Accepted Solution

by:
oBdA earned 300 total points (awarded by participants)
ID: 41859768
The Count property is only present on arrays. If only one object is returned, you have a scalar as result, so there's no Count property.
Easy fix: turn the result into an array (no, this will not create a nested array if more than one mailbox is returned):
$Mailbox = @(Get-Mailbox -Identity "sample" | Select Alias, PrimarySmtpAddress)

Open in new window

3
 
LVL 18

Assisted Solution

by:Peter Hutchison
Peter Hutchison earned 100 total points (awarded by participants)
ID: 41860160
Try using the Measure-object to display a count of objects:

Get-Mailbox -Identity "sample" | Select Alias,PrimarySmtpAddress | Measure-Object
1
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41887606
Sufficient information provided to resolve issue.
0

Featured Post

Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article will help you understand what HashTables are and how to use them in PowerShell.
In this video we show how to create an email address policy 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 Mail Flow…
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now