View Single Post
Old 08-08-2007   #5 (permalink)
Thomas M.


 
 

Re: Add User to AD Group

Whoops! Sorry. You're right, that is from a book on scripting with ADSI.
I had my PowerShell book out at the same time and just cited the wrong book.
Obviously, since the current release of PowerShell supports AD via VBScript,
this would have to be in VBScript as the .vbs file name extension indicates.

I didn't mention the name of the book because I did not want my message to
reflect negatively on the book in the event that the problem was my fault
(i.e.. a missing update, patch, etc.).

At any rate, I will look at the link that you provided and go from there.
Thanks for the help.

--Tom

"Brandon Shell" <tshell.mask@mk.gmail.com> wrote in message
news:OhPwyCW2HHA.3788@TK2MSFTNGP02.phx.gbl...
> 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
>>

>



My System SpecsSystem Spec