Link to home
Start Free TrialLog in
Avatar of ntr2def
ntr2def

asked on

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
Avatar of SubSun
SubSun
Flag of India image

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

Avatar of ntr2def
ntr2def

ASKER

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
testgroup26 group should be populated with users from testgroup26.csv. is it not happening?
Avatar of ntr2def

ASKER

I removed the users to differentiate one user populating groups another file populating users
testgroup102.csv
testgroup26.csv
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..
Avatar of ntr2def

ASKER

i thought i saved it. again testgroup102 only has users whereas testgroup26 only has nested groups.
testgroup26.csv
testgroup102.csv
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..
Avatar of ntr2def

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial