Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Computer to AD Group

Status
Not open for further replies.

dfrey

IS-IT--Management
Jun 22, 2006
5
US
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...

DF
 
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
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn="ComputerName",ou=Computers ,ou=Minneapolis,ou=Central Region,dc="company", dc=com")
objGroup.SetInfo
 
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.
 
I'm glad you show at least something for the forum to have something anchored as a starting point. It is done like this.
[tt]
Set objGroup = GetObject _
("LDAP://cn=XP Coversion[highlight],[/highlight]ou=Groups[highlight],[/highlight]dc=[highlight]C[/highlight]ompan[highlight]y[/highlight],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
[/tt]
 
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))
Case "COMPUTERNAME"
ADSysInfo = ADsys.ComputerName
End Select
End Function
'
Const ADS_PROPERTY_APPEND = 3
'
Set objGroup = GetObject _
("LDAP://cn=Domain XP Coversion,ou=Groups,dc="company name",dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn="&COMPUTERNAME&",ou=Computers ,ou=Minneapolis,ou=Central Region,dc="company name", dc=com")
objGroup.SetInfo
 
I can only conclude you did not read my answer (which I don't claim perfect.)
 
Thanks for the advice this worked....

Set objNetwork = CreateObject("Wscript.Network")
strcomputername = ucase((objnetwork.computername))
msgbox strcomputername
Const ADS_PROPERTY_APPEND = 3
Set objGroup = GetObject _
("LDAP://cn=Domain XP Coversion,ou=Groups,dc=Company name,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn="&strcomputername&",ou=Computers ,ou=Minneapolis,ou=Central Region,dc=Company name, dc=com")
objGroup.SetInfo
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top