Page 1 of 1 1
Topic Options
#120811 - 2004-06-08 04:45 PM Add computer to a group
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
Using kix and adsi to try to add a AD computer to an AD group in the same domain. Searched the forums and cannot seem to find anything....tried running the following code but can't seem to get it to work.

Code:

$pcname="MyComputer"


;Check PC exists in AD
$PC = GetObject("WinNT://MyDomain/$pcname")

;If Exist add to group
If $error=0
$oGroup = ("WinNT://MyDomain/MyGroup,group")
$oGroup.Add ("WinNT://MyDomain/$pcname")
$oGroup.Setinfo
EndIf

Anyone have any idea what is wrong with the above.

Thanks,

Top
#120812 - 2004-06-08 04:54 PM Re: Add computer to a group
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What is
Code:

If $error=0


??

Should it not be -
Code:

If @error=0


??

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#120813 - 2004-06-08 05:00 PM Re: Add computer to a group
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
That is correct....that's a typo sorry. I have @error=0 here and still same problem.
Top
#120814 - 2004-06-08 06:44 PM Re: Add computer to a group
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
anyone??
Top
#120815 - 2004-06-08 06:53 PM Re: Add computer to a group
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
First off, not so sure the WinNT provider can do it... may have to use LDAP. Secondly, does not the computer name always end with a dollar ($) sign?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120816 - 2004-06-08 07:01 PM Re: Add computer to a group
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
End with a $...I don't understand. The Winnt provider can do it with a user account so I just assumed it could do it with a computer account as well...will try LDAP though.
Top
#120817 - 2004-06-08 07:13 PM Re: Add computer to a group
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
i played with it a litle bit trying the WinNT... and was not able to get it to add a computer to a group on my 2003 AD server...

Top
#120818 - 2004-06-08 07:54 PM Re: Add computer to a group
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
The WinNT-name for a computer ends with a dollar-sign as statet by Les
(Pre Windows 200 logon Name)

If the pc and group exists, this will work

Code:

$pcname = "MyComputer"
$Group = "Mygroup"

$oPC = GetObject("WinNT://" + @Domain+ "/" + $pcname + "$$") ; Dollarsign appended to pcname

;If Exist add to group
If VarType($oPC) = 9
$oGroup = GetObject("WinNT://" + @Domain + "/" + $Group + ",group")
If VarType($oGroup) = 9
$oGroup.Add($oPC.adspath)
EndIf
EndIf



-Erik

Top
#120819 - 2004-06-08 07:54 PM Re: Add computer to a group
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The sAMAccountName of a computer ends with a $.

Borrowing from some VBS I came across:
objComputer.Put "sAMAccountName", strComputer & "$"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120820 - 2004-06-08 08:44 PM Re: Add computer to a group
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
Yes...this worked perfectly...I was not aware of the $ thing...once again thanks for the help.
Top
#120821 - 2004-06-12 03:18 PM Re: Add computer to a group
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Shame... The handy dandy search tool found:

link: Add Computer to Active Directory Group
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.065 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org