adding or removing AD groups from a computer

Welcome Forums General PowerShell Q&A adding or removing AD groups from a computer

This topic contains 1 reply, has 2 voices, and was last updated by

 
Moderator
2 years, 3 months ago.

  • Author
    Posts
  • #53326

    Participant
    Points: 0
    Rank: Member

    Is it possible to use a csv or text file with AD groups in it, use a powershell script to reference the csv / text file and add them to the group membership of a computer? or remove them? Thanks for any help in advance.

  • #53330

    Moderator
    Points: 24
    Team Member
    Rank: Member

    That is definitely possible and not too difficult.

    Example (not tested):

    Import-Module -Name ActiveDirectory
    
    $csvPath = 'C:\Scripts\Users.csv'
    $groupName = 'TestGroup1'
    
    $items = Import-CSV -Path $csvPath
    foreach ($item in $items)
    {
        Add-ADGroupMember -Identity $groupName -Members $item.UserName 
    }
    
    foreach ($item in $items)
    {
        Remove-ADGroupMember -Identity $groupName -Members $item.UserName -Confirm:$false
    }
    

The topic ‘adding or removing AD groups from a computer’ is closed to new replies.