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.
techdriveAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
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"
0
 
Britt ThompsonSr. Systems EngineerCommented:
You can add in an additional -NE "Microsoft.com/Accounts" and use a * after the last / in your -like statement
0
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.