Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get-aduser excluding certain OU's

Posted on 2016-11-07
3
Medium Priority
?
117 Views
Last Modified: 2016-11-07
I have staff and student OU's in each of our parent OU's that represent the building they are in.   I am searching the entire AD for a display name and occasionally one of the students will have the same name as a staff member.  I would like to omit any student names from the results.  The staff would be in an OU named staff and the students would be in an OU named students.  There are many different staff and student OU's in our AD.  I need to keep any students out of the results. Can you help with this?

$adduser = "john Doe"
$schoollist = "Kennedy"
$d = Get-Aduser -Filter {displayname -eq $adduser} -Property displayname
add-ADGroupMember $schoollist -Members $d
0
Comment
Question by:Roccat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41877234
$adduser = "john Doe"
$schoollist = "Kennedy"
$d = Get-Aduser -Filter {displayName -eq $adduser} -Property displayname | ? {$_.DistinguishedName -notlike '*,OU=Students,*'}
Add-ADGroupMember $schoollist -Members $d

Open in new window

0
 

Author Comment

by:Roccat
ID: 41877239
Thank you! What does the question mark mean?
 ? {$_.DistinguishedName -notlike '*,OU=Students,*'}
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41877242
It's short for "Where-Object" (and "%" is an alias for "ForEach-Object").
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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