This PowerShell script can be used to add multiple machines to an Active Directory (AD) Group.
This script will prompt you to input the password for the account you specify.
# Add Machines from a csv input file to an Active Directory Group Import-Module ActiveDirectory # Replace GroupName with the name of the AD Group to which you want to add the machines. $ADGroup = "GroupName" # Replace Domain\AccountName with the Active Directory Account to use. $ADCreds = Get-Credential "Domain\AccountName" # Replace C:\Temp\Input.csv with the full path to the CSV file containing the list of machines to add. # The CSV File should be formatted with one Machine Name per line, with a field title of Name $InputFile = "C:\Temp\Input.csv" Import-Csv $InputFile | ForEach-Object { $Name = $_."Name" $Name2 = "$Name$" Add-ADGroupMember $adGroup $Name2 -Credential $ADCreds; Write-Host "- "$Name2" added to "$adGroup}
The input file should be formatted as follows:
Name Machine 1 Machine 2 Machine 3 etc..