computer to multiple AD Groups

Welcome Forums General PowerShell Q&A computer to multiple AD Groups

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
1 year, 6 months ago.

  • Author
    Posts
  • #69427

    Participant
    Points: 0
    Rank: Member

    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?

  • #69432

    Participant
    Points: 21
    Rank: Member

    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}
    
    • #69519

      Participant
      Points: 48
      Rank: Member

      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)
      
  • #69468

    Participant
    Points: 0
    Rank: Member

    Thanks for the help.

The topic ‘computer to multiple AD Groups’ is closed to new replies.