Limbo
(Lurker)
2006-02-16 10:23 PM
Add Computer to Domain Group?

Hoping someone can answer this for me. I am trying to add a compter object to a group object in AD. I've got it working for users, but it's computers I really need it to work for.
I have a script to determine if a computer is a laptop or desktop. I then need these computers adding to an appropriate group so GPOs can be filtered against them.
Here is the code I got working for adding a user (pretty simple)
Code:
$Group=GetObject("WinNT://DomainName/TESTGROUP,group")
$User=GetObject("WinNT://DomainName/TestUserName,user")
$Group.Add($User.ADsPath)


However, when I try to use the following instead it doesn't work and I get the error "COM exception error "Add" ((null) - (null)) [-2147352567/80020009]"
Code:
$Group=GetObject("WinNT://DomainName/TESTGROUP,group")
$Comp=GetObject("WinNT://DomainName/TestCompName,computer")
$Group.Add($Comp.ADsPath)


Is it not possible to add a computer to a group using this method?
All I could find in searching was to add a user to a group.

Wanting to get it working while logged in as Domain Admin, then I'll try to set the security on a group to allow computers to add themselves.

Any help would be great, it's bugging the hell out of me


Howard Bullock
(KiX Supporter)
2006-02-16 10:33 PM
Re: Add Computer to Domain Group?

Try treating the computer as the user account it truly is. The computer's account ends in a "$" sign.

Limbo
(Lurker)
2006-02-16 11:05 PM
Re: Add Computer to Domain Group?

Tried appending $ and $$, but no joy. I get this error instead for both:
COM exception error "Add" (Active Directory - An invalid directory pathname was passed) [-2147352567/80020009]


Howard Bullock
(KiX Supporter)
2006-02-16 11:17 PM
Re: Add Computer to Domain Group?

Comp=GetObject("WinNT://DomainName/TestCompName,computer")


did you treat it as a user?

Comp=GetObject("WinNT://DomainName/TestCompName$$,user")


Limbo
(Lurker)
2006-02-16 11:27 PM
Re: Add Computer to Domain Group?

Your a damn genius, that's what you are!!!

NTDOCAdministrator
(KiX Master)
2006-02-16 11:33 PM
Re: Add Computer to Domain Group?

Just an OLD Codger

Howard's a great guy, just spends too much time on Disney Blast! site


Howard Bullock
(KiX Supporter)
2006-02-19 08:03 AM
Re: Add Computer to Domain Group?

I gave up on the Disney site. I am now a Xbox Halo2 junky...