I have a spreadsheet with the above information and I am trying to figure out a way with powershell to cycle through the list of users and add each one to the group on the right.<\/p>\n
I am very green with powershell and any help would be greatly appreciated.<\/p>\n
Thanks,<\/p>\n
Stephanus<\/p>","upvoteCount":2,"answerCount":6,"datePublished":"2018-09-07T17:02:34.000Z","author":{"@type":"Person","name":"stephanus","url":"https://community.spiceworks.com/u/stephanus"},"acceptedAnswer":{"@type":"Answer","text":"
I think this code will help you. Sorry if there are any mistakes. I’m on mobile device.<\/p>\n
Thanks
\nStephanos<\/p>\n
Import-Module ActiveDitectory\n$data = Import-Csv \"csv-file-path\"\nforeach ($record in $data){\n [string[]]$groups = $record.groups -split ','\n foreach ($group in $groups){\n Add-ADGroupMember -Identity $group Member $record.user}}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2018-09-07T19:24:38.000Z","url":"https://community.spiceworks.com/t/add-users-to-ad-groups/672064/4","author":{"@type":"Person","name":"stephanosconstantinou","url":"https://community.spiceworks.com/u/stephanosconstantinou"}},"suggestedAnswer":[{"@type":"Answer","text":"\n\n\n\n<\/th>\n <\/th>\n<\/tr>\n<\/thead>\n \n\nUser List<\/td>\n Select ALL the department shares the user have access to<\/td>\n<\/tr>\n \nuser1<\/td>\n Administration, Behavioral, Admissions<\/td>\n<\/tr>\n \nuser2<\/td>\n Dietary, Education<\/td>\n<\/tr>\n \nuser3<\/td>\n IT<\/td>\n<\/tr>\n \nuser4<\/td>\n Marketing, Reception<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>I have a spreadsheet with the above information and I am trying to figure out a way with powershell to cycle through the list of users and add each one to the group on the right.<\/p>\n
I am very green with powershell and any help would be greatly appreciated.<\/p>\n
Thanks,<\/p>\n
Stephanus<\/p>","upvoteCount":2,"datePublished":"2018-09-07T17:02:34.000Z","url":"https://community.spiceworks.com/t/add-users-to-ad-groups/672064/1","author":{"@type":"Person","name":"stephanus","url":"https://community.spiceworks.com/u/stephanus"}},{"@type":"Answer","text":"
What have you tried so far ? where are you stuck?<\/p>\n
I assume the spreadsheet is a CSV?<\/p>\n
foreach($line in (import-csv \"c:\\folder\\file.csv\")){\n #do something\n}\n<\/code><\/pre>\nif it is in excel format (xlsx) you might want to convert it, or look into Doug Finke’s ImportExcel Module<\/a><\/p>\nIf you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>