I'm not sure where you got that code, but its not powershell... its
vbscript.
Here is a good post for adding user to a group
http://www.leadfollowmove.com/archiv...ershell-part-2
==== Sample Code ====
$root = [adsi]""
$rootdn = $root.distinguishedName
$userdn = "cn=myuser,cn=users,$rootdn"
$group = [adsi]("LDAP://cn=Domain Admins,cn=Users,$rootdn")
$group.add("LDAP://$userdn")
$group.SetInfo()
================
"Thomas M." <NoEmailReplies@Please.com> wrote in message
news:%23mVZSkV2HHA.1124@TK2MSFTNGP06.phx.gbl...
> I'm new to PowerShell and I'm trying to create a script that will add a
> user to an Active Directory group. I copied the following code out of a
> book into PrimalScript 4.1 Enterprise and modified it for my environment.
> I've sanitized the code (force of habit when posting on the Internet).
>
> xxxx = My division OU
> yyy = My agency OU
> zz = My state
>
> Dim objGroup
>
> set objGroup = GetObject _
>
> ("LDAP://CN=UserRightsExceptions,CN=Groups,CN=UserRightsTesting,CN=xxxx,CN=yyy,DC=state,DC=zz,DC=ads")
> objGroup.add _
>
> ("CN=CXLMTUSR,OU=LimitedUsers,OU=UserRightsTesting,OU=xxxx,OU=yyy,DC=state,DC=zz,DC=ads")
> objGroup.SetInfo
>
> So basically, I want to add the user named CXLMTUSR to the
> UserRightsExceptions group in Active Directory. I have confirmed that
> both distinguished names are correct, assuming no syntax errors. When I
> run the script I get the following error:
>
> <Path>\AddUserToGroup.vbs(3, 1) (null): There is no such object on the
> server.
> Exit code: 0 , 0000h
>
> where <Path> is the full path to the script file.
>
> Can someone show me what I am doing wrong?
>
> --Tom
>