?
Solved

Method of obtaining only users with mailboxes, per OU

Posted on 2014-01-10
5
Medium Priority
?
377 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
[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
  • 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 1000 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 42

Accepted Solution

by:
Adam Brown earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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