Author Posts

April 24, 2017 at 8:11 pm

Hi, I see a lot of examples of adding computers from a list to an AD Group. Does someone have an example of adding multiple AD Groups from a text file to a computer?

April 24, 2017 at 8:38 pm

Assuming you have a csv file you can do something like the following

$computer = get-adcomputer "TestServer"
import-csv "C:\groupsExample.csv")| foreach-object{add-adgroupmember -identity $_.group -members $computer }

if you have a text file without a column header and can't use import-csv you can modify this slightly to get-content

$computer = get-adcomputer "TestServer"
get-content "C:\groupsExample.txt" | foreach-object{add-adgroupmember -identity $_ -members $computer}

April 25, 2017 at 1:37 pm

Thanks for the help.

April 26, 2017 at 2:17 am

I find the *-ADPrincipalGroup[membership] cmdlets are lesser known but could help avoid having to use foreach in this situation.

Add-ADPrincipalGroupMembership -Identity PC001 -MemberOf $(Get-Content .\groups.txt)