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