Solved

[Powershell] Mailbox.Count Issue

Posted on 2016-10-25
4
47 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 15

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 84

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 15

Expert Comment

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

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

In-place Upgrading Dirsync to Azure AD Connect
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this video we show how to create an Accepted Domain 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 >> Ac…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

749 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