Solved

Method of obtaining only users with mailboxes, per OU

Posted on 2014-01-10
5
363 Views
Last Modified: 2014-02-13
Hi,

I hope someone can help and I guess there might be an easy answer to this. I am looking to get a list of users, but only those with mailboxes, and I would like it per OU. In EMC there is a column for OU but annoyingly, this doesn't appear in the list of filters. I'm sure there will be a simple enough way to do this via Powershell, I'm just not sure how!

Thanks in advance...
0
Comment
Question by:ishamsi
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Zephyr ICT
ID: 39770726
In Powershell you can use something like this, but might be too general?

get-mailbox -OrganizationalUnit 'OU=finances,OU=Physical,OU=Accounts,DC=domain,DC=com'

Open in new window

0
 

Author Comment

by:ishamsi
ID: 39770934
Thanks. Yeah, that does work, but I need it to be formatted a bit more nicely and, since there are a lot of OU's, it would be nice if one command could output all of them, but separated by OU. Any ideas?
0
 
LVL 25

Assisted Solution

by:Zephyr ICT
Zephyr ICT earned 250 total points
ID: 39771087
Something like this might work:

$AllMailboxes = @() 
 foreach ($ou in Get-OrganizationalUnit) 
 { 
  $AllMailboxes += Get-Mailbox -OrganizationalUnit $ou.DistinguishedName -ResultSize Unlimited |Select-Object OrganizationalUnit,DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object ` 
{$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}} 
 } 
 $AllMailboxes |Export-Csv c:\test.csv -NoTypeInformation  

Open in new window


Sorry, not a lot of time to test out the script, but it should do the job.
0
 
LVL 38

Accepted Solution

by:
Adam Brown earned 250 total points
ID: 39772131
get-mailbox | select name,primarysmtpaddress,organizationalunit |sort-object organizationalunit | export-csv <file path>

Open in new window


Easiest way to do it right there. You can cut the |export-csv part out if you like to just display it and not output to CSV file.
0
 

Author Closing Comment

by:ishamsi
ID: 39855775
Hi,

Thanks very much for these and apologies about the delay in my response. Both these commands gave me what I needed so I'll split the points. Thanks again.
0

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now