Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, October 27, 2013 12:12 AM
Hi there folks, I'm trying to bulk add users into multiple groups.
I know this has been discussed before, but none of the other examples seem to work for me.
The one closest to my wishes is https://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/4f3efb65-6f13-4519-957f-d053e6f93888/
But this script needs users either to be entered in an array or retrieved from a file with 'gc'.
But then again, you've got two places containing related data. if i do the same thing with below command for single group it works not for mutliple groups
My csv file has two tabs Users group
for e.g
users,group
_SptLamone_50,"ACL_ONE50_NONDATROLES_MACHINEUSER ACL_ONE50_CUSTDATROLE_MACHINEUSER"
What I need is something like this:
Import-module ActiveDirectory
Import-Csv C:\Temp\UsersInGroups.csv | foreach{Add-ADGroupMember -Identity $_.GroupName -Member $_.User
All replies (2)
Sunday, October 27, 2013 12:28 AM âś…Answered
I got the answer from this link i had to only modified the split part (see the bold )
$Items = import-csv .\UserList.csv
$Items | ForEach-Object {
$SamAccountName = $_.SamAccountName
$Groups = ($_.Groups).split(" ")
foreach ($Group in $Groups)
{
"Adding $SamAccountName to the following group: $Group"
Add-ADGroupMember -Identity $Group $SamAccountName
}
}
Thanks
Monday, October 28, 2013 5:55 AM | 1 vote
Hi,
Thanks for your sharing the solution!
Have a nice day!
Regards,
Yan Li
If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.