looking for a posh script that will add members to a group from csv using get-qaduser

trying to develop a script that will add users to an active directory group using get-qaduser or get-qadgroup command from an .csv file
the .csv file contains two columns:

column 1              column 2          
Joes1                   groupName
Joes1                   groupName2
Joes1                   groupName3 ....
Peter1                  groupname
Peter1                  groupname2....

thanks in advance,

S.

siber1Asked:
Who is Participating?
 
soostibiConnect With a Mentor Commented:
This is a very basic prototype:
$csv = import-csv c:\yourfile.csv

$csv | % {
    $user = Get-QADuser -SamAccountName $_.username
    $group = Get-QADGroup -SamAccountName $_.groupname
    if($group -and $group.member -notcontains $user.dn){
        Add-QADGroupMember -Identity $group -Member $user
    }
}

Open in new window

0
 
siber1Author Commented:
perfect as usual!
thx again!
0
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.

All Courses

From novice to tech pro — start learning today.