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?
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}
Thanks for the help.
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)