add users to groups based off file name.

Currently what im doing is I'm importing a list that contains groups names. I then take that list and i want to import the list that matches the group name and add the members in that list in to the groups. Below is what i have so far, however it seems to be adding users to say both the groups

$Domain1 = 'domain.com'

$groups = import-csv .\GlobalExport_$Domain1.csv

foreach($group in $groups) {
$GroupName = ".\"+$Group.samAccountName
Import-csv.\$groupName.csv | foreach {add-qadgroupmember $group.samAccountName -member $_.DN}}

what it does it takes the users from the list and adds them but adds the users from one list to both groups

attached are some files that im using
GlobalExport-domain.com.csv
testgroup26.csv
testgroup102.csv
LVL 1
ntr2defAsked:
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.

SubsunCommented:
The script looks good to me.. but I see many account are there in both group csv. So those accounts will be added to both groups.

Did you test by just adding one user to each group csv?

For example, add user "Test User133" in TestGroup26.csv and "TestGroup99" in TestGroup102.csv
0
SubsunCommented:
In your example.. following accounts are available in both groups csv. So they will be added to both groups..
TestGroup99
TestGroup98
TestGroup97
TestGroup96
TestGroup95
TestGroup94
TestGroup93
testUser126
testUser125
testUser124
testUser123
testUser122
testUser121
testUser120
testUser119
testUser118
testUser117
testUser116
testUser115
testUser114
testUser113
testUser112
testUser111
testUser110
testUser109
testUser108
testUser107
testUser106
testUser105
testUser104
testUser103
testUser102
testUser101
testUser100
testUser12
testUser11
testUser10
testUser1

Open in new window

0
ntr2defAuthor Commented:
so i removed the accounts from group 102 and just left the groups

TestGroup99
TestGroup98
TestGroup97
TestGroup96
TestGroup95
TestGroup94
TestGroup93

when i run it, it populates Testgroup102 with the nested groups but the testUsers are not populated in TestGroup26
0
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

SubsunCommented:
testgroup26 group should be populated with users from testgroup26.csv. is it not happening?
0
ntr2defAuthor Commented:
I removed the users to differentiate one user populating groups another file populating users
testgroup102.csv
testgroup26.csv
0
SubsunCommented:
I still see duplicate values in both files. I would suggest you to add just one user in each input file to test the script..
0
ntr2defAuthor Commented:
i thought i saved it. again testgroup102 only has users whereas testgroup26 only has nested groups.
testgroup26.csv
testgroup102.csv
0
SubsunCommented:
As per the input file TestGroup26 should be populated with the nested groups and TestGroup102 with users. Looking at the code it should work fine.. I have no connectivity to my lab to test it right now..
0
ntr2defAuthor Commented:
huh, i re ran it again and it seems to be working. i guess having a lot of the duplicate users and groups in the same files did throw me off
0
SubsunCommented:
Great!
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
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
Active Directory

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.