adding or removing AD groups from a computer

This topic contains 1 reply, has 2 voices, and was last updated by  Daniel Krebs 1 year, 10 months ago.

  • Author
  • #53326


    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

    Daniel Krebs

    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.