Join a computer to an AD group with javascript

From The IT Community
Jump to: navigation, search




Sometimes you want to automatically join a computer to an active directory group, for example if you are using it in a SCCM task sequence.


Here is how to join a computer to an AD group with javascript:

  • Create a new file named joingroup.vbs with the following content:
Set adSys = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & adSys.ComputerName)
Set objGroup = GetObject("LDAP://cn=name_of_the_group,OU=computers,DC=theitcommunity,DC=com)
If Not objGroup.ismember(objComputer.adsPath) Then
   objGroup.Add(objComputer.AdsPath) 'this works too
   objGroup.SetInfo
End If
  • Change the line where you get the objGroup to an LDAP path that reflects your group.
  • Execute the script in a cmd which you opened as a user who has the rights to join computer objects into this group.


Note: if you want to use this in a SCCM task sequence, remember that you also have to run as a user with enough rights.



Was this article helpful? Then please donate to keep The IT Community alive...

If you found this article helpful please share it, comment and help others by writing your own article.






Translate this page:




Articles found in the same category:
(max. 20 shown)