Solved

Populating AD Security Groups based on AD attribute

Posted on 2013-06-18
3
1,424 Views
Last Modified: 2013-06-19
Hi Experts,

Is there a way to script the following:

If user is member of a certain department (AD Attribute) then populate a certain security group i.e. make the user a member of that security group?

Domain is Windows 2008 R2

TIA
0
Comment
Question by:abhijitm00
[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 40

Expert Comment

by:Subsun
ID: 39257209
Try somethign lke..
Get-ADuser -filter {Department -eq "Marketing"} | %{Add-ADGroupMember "Marketing Group" $_.SamAccountName}

Open in new window

0
 

Author Comment

by:abhijitm00
ID: 39257795
Thanks Subsun, this seems to work. Is there a way to restrict this to a certain OU?
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39257819
Try..
Get-ADUser -SearchBase 'OU=UserAccounts,DC=contoso,DC=local' -filter {Department -eq "Marketing"} | %{Add-ADGroupMember "Marketing Group" $_.SamAccountName}

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

724 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