Menu Close

How to create multiple groups in AD with a batch script

Assuming you have a text file (e.g. C:\ADGroups.txt) containing multiple Active Directory (AD) Groups with one AD group per line, you may use an MS-DOS script similar to the following to create all those AD Groups in your Active Directory domain.

for /F "tokens=* delims= " %%G in (C:\ADGroups.txt) do (
 dsadd group CN="%%G",OU="Human Resources",OU="IT",DC=MYAD,DC=CYBERGAV,DC=IN
)

NOTE:
(1) If you are typing the script above at the MS-DOS command prompt, then replace %%G by %G.
(2) The “for” statement above, ensures that AD Groups containing blankspaces are read correctly.

VN:F [1.9.22_1171]
Rating: +6 (from 6 votes)
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *