Solved

Method of obtaining only users with mailboxes, per OU

Posted on 2014-01-10
5
370 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 39

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

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

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
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
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…

776 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