Solved

Get-aduser excluding certain OU's

Posted on 2016-11-07
3
31 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
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 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 83

Expert Comment

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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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