Powershell to Add Bulk Computers (Host Name Format) to a Global Group in Active Directory
Hello experts,
I need to add 5500 computer objects to a global group in Active Directory. Does anybody have a handy script (VB or powershell) that will read the list of computers from txt or csv and send an output result which ones were successful and not because it was already in the group.
Please help!
Thank you.
PowershellVB Script
Last Comment
IT _Admin0723
8/22/2022 - Mon
Amit Kumar
prepare a csv file with computer Name and run below powershell:
Computer name should be mentioned like as below mentioned and powershell should be run in AD powershell module.
Comp1$
Comp2$
Comp3$
Change $groupname variable in script with your group name
import-module ActiveDirectory$groupname = "please specify group name here"$comps = Import-csv c:\comp.csvforeach ($comp in $comps) {ADD-ADGroupMember $groupname –members $compwrite-host "$comp is added to the $groupname."}
try this one, and please copy this code in a text file then save it it to .ps1 file then run it.
for report what you can do just export members of that group and compare it with your csv file that way will be good else it will take a lot time to verify it by script, because all the time we will have check if that computer is added or not and by default it does not mark a flag which can be compared with if/else condition.
Please paste error while running this code.
import-module ActiveDirectory$comps = Import-csv c:\comp.csvforeach ($comp in $comps) {$groupname = "please specify group name here"ADD-ADGroupMember -id $groupname –members $compwrite-host "$comp is added to the $groupname."}
Computer name should be mentioned like as below mentioned and powershell should be run in AD powershell module.
Comp1$
Comp2$
Comp3$
Change $groupname variable in script with your group name
Open in new window