Avatar of ddotson
ddotson
 asked on

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

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
PowershellExchangeActive Directory

Avatar of undefined
Last Comment
ddotson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rajitha Chimmani

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ddotson

ASKER
That works perfectly.  Thank you!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy