Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ddotson
ddotson

ASKER

That works perfectly.  Thank you!