Solved

[Powershell] Mailbox.Count Issue

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

Is Your AD Toolbox Looking More Like a Toybox?

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

Title # Comments Views Activity
Creating 2 network Adapters via PowerCli 7 35
profile account in outlook problem 3 42
Exchange 2013 Message Tracking 3 33
While loop multiple conditions 5 30
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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...
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.

737 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