Solved

Need to get list of Mailboxes in an OU, Not Sub-OU's

Posted on 2014-11-19
2
3,305 Views
Last Modified: 2014-11-19
I'm struggling to write a Powershell command that will list all of the mailboxes in an OU, but leave out the mailboxes in sub-OU's.

I've tried:

get-mailbox -OrganizationalUnit "OU=Disabled Accounts,DC=domain,DC=com" | where {$_.distinguishedName -like "CN=*,OU=Disabled*"} | select-object name

Open in new window


get-mailbox -filter distinguishedName -like "CN=*,OU=Disabled Accounts,DC=domain,DC=COM"

Open in new window


get-mailbox -OrganizationalUnit "OU=Disabled Accounts,DC=Leavitt,DC=COM" -filter "distinguishedName -like 'CN=*,OU=Disabled Accounts,DC=domain,DC=COM'"

Open in new window


I'm just not getting this right.  Can someone help?

Thanks,

Dan
0
Comment
Question by:ddotson
2 Comments
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 40453077
First get the canonical name of the organizational unit and try the following command

Get-Mailbox -Resultsize unlimited | where {$_.organizationalunit -eq "domain.com/Disabled Accounts"}
0
 

Author Comment

by:ddotson
ID: 40453128
That works perfectly.  Thank you!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

11 Experts available now in Live!

Get 1:1 Help Now