Add multiple computers to AD Group

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Dale Longstaff Dale Longstaff 2 months, 4 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45342
    Profile photo of Dale Longstaff
    Dale Longstaff
    Participant

    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.....

    #Test

    [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.

    THanks.

    #45360
    Profile photo of Paul Frankovich
    Paul Frankovich
    Participant

    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

    #45377
    Profile photo of Dale Longstaff
    Dale Longstaff
    Participant

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.