Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Add Computer to AD Group

Add Computer to AD Group

I am working on my companies workstation image.  I am trying to write a script for all Computers built with this image to add themselves to a specific Active Directory Group.  At first I thought a simple bat file using "dsmod" would work.  However I realized I needed a way to make the batch file to vary with the computers name.  Any suggestions would be appreciated...


RE: Add Computer to AD Group

What have you tried sofar?

RE: Add Computer to AD Group

I am not sure where to begin... this is what I tried to this point.

Set objGroup = GetObject _
    ("LDAP://cn=XP Coversion;ou=Groups;dc="Company",dc=com")
'  "XP Conversion" is the group I would like it to be placed
    "member", Array("cn="ComputerName",ou=Computers ,ou=Minneapolis,ou=Central Region,dc="company", dc=com")

RE: Add Computer to AD Group

I forgot to put on the initial post that I figured a Batch file wouldnt work so I attempted to write a vbs script to get it to work.  I figured if I could make the script work with one computer then I could move on to making it work on any computer the script was run on.

RE: Add Computer to AD Group

I'm glad you show at least something for the forum to have something anchored as a starting point. It is done like this.

Set objGroup = GetObject _
    ("LDAP://cn=XP Coversion,ou=Groups,dc=Company,dc=com")
'  "XP Conversion" is the group I would like it to be placed
Set ocomputer=GetObject _
    ("LDAP://cn=ComputerName,ou=Computers," & _
    "ou=Minneapolis,ou=Central Region,dc=company,dc=com")
objGroup.add ocomputer.adspath
'or simply this instead
'objGroup.add "LDAP://cn=ComputerName,ou=Computers," & _
'    "ou=Minneapolis,ou=Central Region,dc=company,dc=com"
'add error control as needed and not to forget cleaning up

RE: Add Computer to AD Group

This is what I got so far... The script fails at line 16.  Am I doing something wrong with my COMPUTERNAME variable?

Function ADSysInfo(strADSysInfo)
 Dim ADsys
   Set ADsys = CreateObject("ADSystemInfo")
   Select case (ucase(strADSysInfo))
         ADSysInfo = ADsys.ComputerName
   End Select
End Function
Set objGroup = GetObject _
    ("LDAP://cn=Domain XP Coversion,ou=Groups,dc="company name",dc=com")
    "member", Array("cn="&COMPUTERNAME&",ou=Computers ,ou=Minneapolis,ou=Central Region,dc="company name", dc=com")

RE: Add Computer to AD Group

I can only conclude you did not read my answer (which I don't claim perfect.)

RE: Add Computer to AD Group

Thanks for the advice this worked....

Set objNetwork = CreateObject("Wscript.Network")
strcomputername = ucase((objnetwork.computername))
msgbox  strcomputername
Set objGroup = GetObject _
    ("LDAP://cn=Domain XP Coversion,ou=Groups,dc=Company name,dc=com")
    "member", Array("cn="&strcomputername&",ou=Computers ,ou=Minneapolis,ou=Central Region,dc=Company name, dc=com")

RE: Add Computer to AD Group

i would prob use the WinNT provider in your case, well i only say that because you are making a implicit link between a machines netbios name and its LDAP ADsPath....this link will not always hold true

Red Flag This Post

Please let us know here why the post below is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close