Add multiple computers to AD Group

This topic contains 2 replies, has 2 voices, and was last updated by  Dale Longstaff 2 years ago.

  • Author
  • #45342

    Dale Longstaff

    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.


  • #45360

    Paul Frankovich

    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

You must be logged in to reply to this topic.