Hi, everyone.
I am going to create 10 users who names client 1 to client 10, and then move
them to the appointed OU which names "SYS"

I prepared 2 vbscripts.

1st: create 10 users:

source code:

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
For i = 1 To 10
Set objLeaf = objContainer.Create("User", "cn=Client" & i)
objLeaf.Put "sAMAccountName", "UserNo" & i
objLeaf.SetInfo
Next
WScript.Echo "Users created."

2st: move them to OU (the name for ou is "SYS")

Const ADS_PROPERTY_APPEND = 3
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
Set objOU = objContainer.Create("OU", "cn=SYS")
objOU.Put "sAMAccountName","SYS"
objOU.SetInfo
For i = 1 To 10
strDN = ",cn=Users," & objRootDSE.defaultNamingContext
objOU.PutEx ADS_PROPERTY_APPEND, "member", _
Array("cn=UserNo" & i & strDN)
objOU.SetInfo
Next
WScript.Echo "Users added to the OU."

But , oh no, script failed.

who can tell me what's wrong with "it" (I mean the script)?

Thanks for everyone.

Hope everything goes well with you.

KejiaLi
coming from China
email: kejiali@gmail.com

RE: About create users and move them to appointed OU. by Darren

Darren
Wed Aug 16 13:51:04 CDT 2006

Hi could you tell me if the OU SYS is nested or at the route of AD tree

Daz

"KejiaLi" wrote:

> Hi, everyone.
> I am going to create 10 users who names client 1 to client 10, and then move
> them to the appointed OU which names "SYS"
>
> I prepared 2 vbscripts.
>
> 1st: create 10 users:
>
> source code:
>
> Set objRootDSE = GetObject("LDAP://rootDSE")
> Set objContainer = GetObject("LDAP://cn=Users," & _
> objRootDSE.Get("defaultNamingContext"))
> For i = 1 To 10
> Set objLeaf = objContainer.Create("User", "cn=Client" & i)
> objLeaf.Put "sAMAccountName", "UserNo" & i
> objLeaf.SetInfo
> Next
> WScript.Echo "Users created."
>
> 2st: move them to OU (the name for ou is "SYS")
>
> Const ADS_PROPERTY_APPEND = 3
> Set objRootDSE = GetObject("LDAP://rootDSE")
> Set objContainer = GetObject("LDAP://cn=Users," & _
> objRootDSE.Get("defaultNamingContext"))
> Set objOU = objContainer.Create("OU", "cn=SYS")
> objOU.Put "sAMAccountName","SYS"
> objOU.SetInfo
> For i = 1 To 10
> strDN = ",cn=Users," & objRootDSE.defaultNamingContext
> objOU.PutEx ADS_PROPERTY_APPEND, "member", _
> Array("cn=UserNo" & i & strDN)
> objOU.SetInfo
> Next
> WScript.Echo "Users added to the OU."
>
> But , oh no, script failed.
>
> who can tell me what's wrong with "it" (I mean the script)?
>
> Thanks for everyone.
>
> Hope everything goes well with you.
>
> KejiaLi
> coming from China
> email: kejiali@gmail.com
>
>
>