Powershell Bulk add many members to many Groups

Hi ,
anyonecan help me with this one? I'm alway getting sty like identity problem.
Import-Csv "C:\Scripts\Import Bulk Users into bulk groups\bulkgroups.csv" | 
ForEach { get-aduser $_.Accountname | add-adgroupmember $_.Group}

Open in new window






Group             Accountname
group1            user1
group77          user2
group1            user3
group2            user4
group2            user5
group3            user6
group3            user7
group3            user8
group4            user9
group5            user10
LVL 2
Mandy_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joseph MoodyBlogger and wearer of all hats.Commented:
Try this modification:

Import-Csv "C:\Scripts\Import Bulk Users into bulk groups\bulkgroups.csv" | 
ForEach ($User in Users) { 
add-adgroupmember  - identity $User.Group -member $user.accountname}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mandy_Author Commented:
this i have already tried without success
0
Brad GrouxSenior Manager (Wintel Engineering)Commented:
I believe either one of the following should be of some help -

http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Bulk-AD-Group-4d873f35

###########################################################  
# AUTHOR  : Marius / Hican - http://www.hican.nl - @hicannl   
# DATE    : 08-08-2012 
# EDIT    : 16-11-2012 
# CHANGES : Added functionality for duplicate OU names and 
#           changed the input file slightly because of this 
# COMMENT : This script does a bulk creation of Groups in 
#           Active Directory based on an input csv and the 
#           Active Directory Module.  
###########################################################  
Import-Module ActiveDirectory 
#Import CSV 
$csv = @() 
$csv = Import-Csv -Path "C:\Temp\bulk_input.csv" 
 
#Get Domain Base 
$searchbase = Get-ADDomain | ForEach {  $_.DistinguishedName } 
 
#Loop through all items in the CSV 
ForEach ($item In $csv) 
{ 
  #Check if the OU exists 
  $check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)") 
   
  If ($check -eq $True) 
  { 
    Try 
    { 
      #Check if the Group already exists 
      $exists = Get-ADGroup $item.GroupName 
      Write-Host "Group $($item.GroupName) alread exists! Group creation skipped!" 
    } 
    Catch 
    { 
      #Create the group if it doesn't exist 
      $create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase)) 
      Write-Host "Group $($item.GroupName) created!" 
    } 
  } 
  Else 
  { 
    Write-Host "Target OU can't be found! Group creation skipped!" 
  } 
}

Open in new window


... or ...

http://gallery.technet.microsoft.com/scriptcenter/Bulk-Add-Multiple-User-cea37238
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Mandy_Author Commented:
Thats a nice script to create groups but i want to add for example  30 user to 20 different groups
0
Mandy_Author Commented:
Dear experts,

with this code below i'm always getting:
Add-ADGroupMember : The argument for the Parameter "Identity" cannot be checked. The Argument is NULL
Any idea what the problem could be?

Import-Module ActiveDirectory
Import-CSV c:\list.csv | %{
$usr=Get-ADUser $_."user"
$usrdg = $usr.distinguishedName
$grp=Get-ADGroup $_."group"
$grpDG = $grp.distinguishedName
Add-ADGroupMember -Identity $grpDG -Member $usrdg
} 

Open in new window

0
Mandy_Author Commented:
here's the csv
list.csv
0
Mandy_Author Commented:
I found the problem with csv it should be this form below but the script still not add all users to all groups.
Only user1 to group1 and so on.  Could anybody help me?

"user","group"
"User1","group1"
"User2","group2"
"User3","group3"
"User4","group4"

Open in new window

0
Mandy_Author Commented:
import-csv c:\temp\list6.csv | Foreach-Object {add-adgroupmember -Identity $_.group -Members $_.user}

Open in new window


i found this one but same effect as above
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.