# add user(s) from CSV file 1 to Adgroups from CSV file 2

**URL:** <https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440>\
**Category:** PowerShell Help\
**Created:** [April 24, 2019, 4:47am UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440 "2019-04-24T04:47:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirano](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@sirano](https://forums.powershell.org/u/sirano)\
**Post date:** [April 24, 2019, 4:47am UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440/1 "2019-04-24T04:47:16Z")

</div>

add user(s) from CSV file 1 to Adgroups from CSV file 2 till end of file

How can I make a script from this line with above wish:

Add-ADGroupMember -Identity “groupname” -Members “username”

&nbsp;

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 24, 2019, 4:49am UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440/2 "2019-04-24T04:49:01Z")

</div>

I’ve moved this to general Q&A, as it was certainly less like website feedback.

What have you tried so far, beyond the line to get group members? Have you ever output anything to a file in PowerShell?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 24, 2019, 5:48am UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440/3 "2019-04-24T05:48:27Z")

</div>

To get you started you should read the help for at least the following cmdlets:  
[Import-Csv](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-5.1),  
[Foreach-Object](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-5.1),  
[Add-ADPrincipalGroupMembership](https://docs.microsoft.com/en-us/powershell/module/addsadministration/add-adprincipalgroupmembership?view=win10-ps)  
and maybe  
[Select-Object](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-5.1),  
[about\_Foreach](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_foreach?view=powershell-5.1)  
and  
[Add-ADGroupMember](https://docs.microsoft.com/en-us/powershell/module/addsadministration/add-adgroupmember?view=win10-ps).  
You should always read the **COMPLETE** help of the cmdlets you’re about to use … **including all examples**! 😉

---

<div class="post-metadata">

**Author:** ![tethylis](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@tethylis](https://forums.powershell.org/u/tethylis)\
**Post date:** [April 24, 2019, 7:41am UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440/4 "2019-04-24T07:41:53Z")

</div>

If you’re iterating through two csv’s, you might want to use a nested foreach() setup. One foreach to go through each user, then another foreach to add that specific user to a your list of AD groups. If you read the links that Olaf posted, I’m sure you’ll be able to start writing something on your own and ask for more specific help as needed.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/add-user-s-from-csv-file-1-to-adgroups-from-csv-file-2/12440/5 "2024-05-16T20:32:57Z")

</div>


