?
Solved

[Powershell] Mailbox.Count Issue

Posted on 2016-10-25
4
Medium Priority
?
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:Todd Nelson
Todd Nelson earned 400 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 85

Accepted Solution

by:
oBdA earned 1200 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 20

Assisted Solution

by:Peter Hutchison
Peter Hutchison earned 400 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 16

Expert Comment

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

Featured Post

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
New style of hardware planning for Microsoft Exchange server.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 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