powershell getting user in sub-OU's

I have a powershell script that goes and gets

Import-Csv c:\importfile.csv | ForEach-Object {
    Get-Mailbox $_.'User-email' | where {$_.organizationalunit -LIKE "Microsoft.com/User Accounts/"}

Open in new window

presently I get users only in the user accounts OU. What I would like to do is grab any user in a sub ou under User accounts.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

FOXConnect With a Mentor Active Directory/Exchange EngineerCommented:
The below will get all users in that OU and the sub OUs

Get-ADuser -filter * -searchbase "ou=User Accounts,dc=microsoft,dc=com"
Britt ThompsonSr. Systems EngineerCommented:
You can add in an additional -NE "Microsoft.com/Accounts" and use a * after the last / in your -like statement
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.