Author Posts

September 3, 2016 at 6:23 am

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.

September 3, 2016 at 6:35 am

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
}