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

x
?
Solved

Adding users into group automatically - Windows 2008 R2

Posted on 2013-05-19
9
Medium Priority
?
160 Views
Last Modified: 2013-07-29
I have csv file containing list of sAMAccountNames of the users, I want to add all users into group automatically without manual intervention.

How can this be done. Do i need to use script?

thanks
0
Comment
Question by:tech2010
[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
  • 5
  • 4
9 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39178205
here's a powershell script to add users to group.
change the csv file and the group name.
this script code assume no header in the csv.
Import-CSV p:\test.Csv | %{add-Adgroupmember -Identity 'AD_Group' -members $_}

Open in new window

0
 

Author Comment

by:tech2010
ID: 39178378
How to create the script, is it with .ps1

Also how it will run as schedule task? I have UAC enabled so how can i run this as administrator?
0
 

Author Comment

by:tech2010
ID: 39178388
Also if a user already member of the group, can we put someone in the script e.g if user is member of the group then don't attempt to add into the group otherwise it will error. I would also like to email output result of added users into group.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39178434
save this as xxx.ps1:
Import-CSV p:\test.Csv | %{
$user = $_
if(@($members | Where-Object{$_.Name -eq "Ariel Fridman"}).Count -eq 0){
add-Adgroupmember -Identity 'AD_Group' -members $user
}
}

Open in new window

how often would u like to run this as task scheduler?
0
 

Author Comment

by:tech2010
ID: 39178619
do i need to run this on domain controller or can i run this even on the server where RSAT tools are installed?

if(@($members | Where-Object{$_.Name -eq "Ariel Fridman"}).Count -eq 0){

What is Ariel Fridman? can you explain what this statement means?
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 1500 total points
ID: 39179328
Sorry my mistake:
Import-CSV p:\test.Csv | %{
$user = $_
if(@($members | Where-Object{$_.Name -eq $user}).Count -eq 0){
add-Adgroupmember -Identity 'AD_Group' -members $user
}
}
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39179330
Save it as xxx.ps1 and run it from command line:
Powershell xxx.ps1

Make sure to update the csv file path in the script and the group name
0
 

Author Comment

by:tech2010
ID: 39179470
I want to automate this and run this as schedule task daily.

Also, I want to email the results/output of this script that what are the users added into the group? How to do this? thanks

So tell me what your script will do, will it check if user exist in the group then it will skip and end the script but if user not already in the list then i will add? thanks
0
 

Author Comment

by:tech2010
ID: 39179479
Also, in my csv file has header 'SAM Account Name' so i guess variable in the script will be like this $user = $_"SAM Account Name"

please verify and update the script.

please also read my last post

many thanks
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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

636 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