Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Add User to AD Group

Reply
 
Old 08-07-2007   #1 (permalink)
Thomas M.
Guest


 
 

Add User to AD Group

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
Old 08-07-2007   #2 (permalink)
Brandon Shell
Guest


 
 

Re: Add User to AD Group

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
Old 08-07-2007   #3 (permalink)
Marco Shaw
Guest


 
 

Re: Add User to AD Group

Thomas M. wrote:
> 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).


>
> <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?


I'm sorry, everything you mention is pointing to VBScript (including the
.vbs extension of the file you're running).

You're looking to make your existing VBScript run or want some help
porting it to PowerShell.

PowerShell's 'scripting engine' is very different from VBScript, and
PowerShell scripts are normally saved with a .ps1 extension.

Marco
My System SpecsSystem Spec
Old 08-08-2007   #4 (permalink)
Karl Mitschke
Guest


 
 

Re: Add User to AD Group

"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


Tom;

I'm in the same state, same division.

I just did this for a 130 user list, I can send some code if you'd like.

Karl


My System SpecsSystem Spec
Old 08-08-2007   #5 (permalink)
Thomas M.
Guest


 
 

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
Old 08-08-2007   #6 (permalink)
Thomas M.
Guest


 
 

Re: Add User to AD Group


"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:e02EHEW2HHA.1208@TK2MSFTNGP03.phx.gbl...
> Thomas M. wrote:
>> 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).

>
>>
>> <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?

>
> I'm sorry, everything you mention is pointing to VBScript (including the
> .vbs extension of the file you're running).
>
> You're looking to make your existing VBScript run or want some help
> porting it to PowerShell.
>
> PowerShell's 'scripting engine' is very different from VBScript, and
> PowerShell scripts are normally saved with a .ps1 extension.
>
> Marco


Yeah. I had both my PowerShell and my book on ADSI out and I cited the
wrong book by mistake. I'm green when it comes to scripting, but not that
green! It was just a silly oversight on my part. I apologize for the
confusion.

It is written in VBScript and I'm running it in PrimalScript 4.1 Enterprise.
When I looked at the book last night I was under the impression that the
section of code given was complete, but looking at it again this morning it
looks like the example given may assume that other things have been done
first. I skimmed the book last night to see if that was the case, but
perhaps I missed something. I will go back a review it more closely.

Brandon also posted a link to an article so I will review that as well.
Let's consider this one closed. If after digging into it a bit more I still
have questions, I will post a new message.

Thanks for your help!

--Tom


My System SpecsSystem Spec
Old 08-08-2007   #7 (permalink)
Oisin Grehan
Guest


 
 

Re: Add User to AD Group

On Aug 8, 12:21 pm, "Thomas M." <NoEmailRepl...@Please.com> wrote:
> "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
>
> news:e02EHEW2HHA.1208@TK2MSFTNGP03.phx.gbl...
>
>
>
>
>
> > Thomas M. wrote:
> >> 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).

>
> >> <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?

>
> > I'm sorry, everything you mention is pointing to VBScript (including the
> > .vbs extension of the file you're running).

>
> > You're looking to make your existing VBScript run or want some help
> > porting it to PowerShell.

>
> > PowerShell's 'scripting engine' is very different from VBScript, and
> > PowerShell scripts are normally saved with a .ps1 extension.

>
> > Marco

>
> Yeah. I had both my PowerShell and my book on ADSI out and I cited the
> wrong book by mistake. I'm green when it comes to scripting, but not that
> green! It was just a silly oversight on my part. I apologize for the
> confusion.
>
> It is written in VBScript and I'm running it in PrimalScript 4.1 Enterprise.
> When I looked at the book last night I was under the impression that the
> section of code given was complete, but looking at it again this morning it
> looks like the example given may assume that other things have been done
> first. I skimmed the book last night to see if that was the case, but
> perhaps I missed something. I will go back a review it more closely.
>
> Brandon also posted a link to an article so I will review that as well.
> Let's consider this one closed. If after digging into it a bit more I still
> have questions, I will post a new message.
>
> Thanks for your help!
>
> --Tom- Hide quoted text -
>
> - Show quoted text -


If you do decide to take the PowerShell route, your life with AD will
be immeasurably easier with:

http://www.quest.com/activeroles-server/arms.aspx

- Oisin

My System SpecsSystem Spec
Old 08-08-2007   #8 (permalink)
Thomas M.
Guest


 
 

Re: Add User to AD Group


"Oisin Grehan" <oising@gmail.com> wrote in message
news:1186590745.161424.149360@m37g2000prh.googlegroups.com...
> On Aug 8, 12:21 pm, "Thomas M." <NoEmailRepl...@Please.com> wrote:
>> "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
>>
>> news:e02EHEW2HHA.1208@TK2MSFTNGP03.phx.gbl...
>>
>>
>>
>>
>>
>> > Thomas M. wrote:
>> >> 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).

>>
>> >> <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?

>>
>> > I'm sorry, everything you mention is pointing to VBScript (including
>> > the
>> > .vbs extension of the file you're running).

>>
>> > You're looking to make your existing VBScript run or want some help
>> > porting it to PowerShell.

>>
>> > PowerShell's 'scripting engine' is very different from VBScript, and
>> > PowerShell scripts are normally saved with a .ps1 extension.

>>
>> > Marco

>>
>> Yeah. I had both my PowerShell and my book on ADSI out and I cited the
>> wrong book by mistake. I'm green when it comes to scripting, but not
>> that
>> green! It was just a silly oversight on my part. I apologize for the
>> confusion.
>>
>> It is written in VBScript and I'm running it in PrimalScript 4.1
>> Enterprise.
>> When I looked at the book last night I was under the impression that the
>> section of code given was complete, but looking at it again this morning
>> it
>> looks like the example given may assume that other things have been done
>> first. I skimmed the book last night to see if that was the case, but
>> perhaps I missed something. I will go back a review it more closely.
>>
>> Brandon also posted a link to an article so I will review that as well.
>> Let's consider this one closed. If after digging into it a bit more I
>> still
>> have questions, I will post a new message.
>>
>> Thanks for your help!
>>
>> --Tom- Hide quoted text -
>>
>> - Show quoted text -

>
> If you do decide to take the PowerShell route, your life with AD will
> be immeasurably easier with:
>
> http://www.quest.com/activeroles-server/arms.aspx
>
> - Oisin
>


Yeah, we're having an internal discussion on using those. I'd like to use
them, but we have to coordinate with other units too, so we'll see what they
have to say.

--Tom


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Create user group in vista basic without the user and group manager window Vista security
add user to group /group scope - Global /Group type - Security PowerShell
Set Group Policy different for each user group? System Security
Add user to a group? PowerShell
ADD USER TO GROUP ?? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46