Solved

Adding users into group automatically - Windows 2008 R2

Posted on 2013-05-19
9
151 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
  • 5
  • 4
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:tech2010
Comment Utility
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:
sedgwick earned 500 total points
Comment Utility
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:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now