Author Posts

June 30, 2016 at 10:59 am

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.

June 30, 2016 at 1:33 pm

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