Solved

[Powershell] Mailbox.Count Issue

Posted on 2016-10-25
4
38 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 19

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Find out what you should include to make the best professional email signature for your organization.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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