Add multiple computers to AD Group

Hello Guys,

I have been tasked to script the process of adding multiple Hostnames to an AD Security Group (preferably prompted by a VB textbox).

So far i have this…


[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null

$ComputerName = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter a Computer Name”, “Computer”, “$env:computername”)
$ADGroupName = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter name of Software”, “ADGroup”, “$env:ADGroup”)

add-ADGroupMember -Identity $ComputerName $ADGroupName

I am a complete Powershell noob and i’m rather stuck on how this cmdlet works as i cannot seem to get it right… For a start, the variables $Computername and $ADGroupName input boxes appear right at the start before the script calls them, which i don’t know how to stop… I also have no idea how to enter multiple Hostnames into the one input box and ask Powershell to filter through the list and individually add each Hostname to the specified group.

Any help is appreciated.


You could always do something like this:

$Computers = $ComputerName.Split(",").Trim()
ForEach ($Computer in $Computers)
     Add-ADGroupMember -Identity $ADGroupName -Members "$Computer$"

The Identity parameter is meant for the group name, not the account you want to add

Thank you!