Solved

powershell getting user in sub-OU's

Posted on 2016-07-21
2
13 Views
Last Modified: 2016-07-22
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.
0
Comment
Question by:techdrive
2 Comments
 
LVL 16

Accepted Solution

by:
FOX earned 500 total points
ID: 41722984
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
 
LVL 30

Expert Comment

by:renazonse
ID: 41723001
You can add in an additional -NE "Microsoft.com/Accounts" and use a * after the last / in your -like statement
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question