adding or removing AD groups from a computer

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 3 months ago.

  • Author
    Posts
  • #53326
    Profile photo of Tony Rodal
    Tony Rodal
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
    }
    

You must be logged in to reply to this topic.