Home All Groups Group Topic Archive Search About

How to create users using VBS from an Excel sheet.

Author
8 Feb 2006 4:39 PM
Lion
Help please,

I'm trying to put a script that will crate users from an Excel sheet and I
get this error:

Line: 11
Char: 5
Error: The directory property cannot be found in the cache.
Code: 8000500D
Source: Active Directory

Which point to this line of code: objUser.AccountDisabled = FALSE  If I rem
this out it creates the account but is disabled.

Also is it possible to make the crated accounts members of the particular
groups using the same script.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
    Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
1).Value)
    objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
    objUser.GivenName = objExcel.Cells(intRow, 3).Value
    objUser.SN = objExcel.Cells(intRow, 4).Value
    objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
    objUser.AccountDisabled = FALSE
    objUser.SetInfo
    intRow = intRow + 1
Loop
objExcel.Quit

Author
8 Feb 2006 7:34 PM
Umesh Thakur
When I was creating users using excel file, I encountered the same error.
However, I strongly believe that this error is not caused by this line:

objUser.AccountDisabled = FALSE

You will get this error if you try to set any Terminal Server specific
property
and you are using Windows2000 server as DC. So, I suspect, this is caused by
this line:

objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value

try to comment this line, and execute the script. it should work fine.

Windows 2000 server does not allow you to access Terminal Server specific
properties using script, you MUST use WTS API to do that. tscmd.exe is a
freeware tool that uses WTS API and allows you to modify user's terminal
services specific properties.


--

Show quoteHide quote
"Lion" wrote:

> Help please,
>
> I'm trying to put a script that will crate users from an Excel sheet and I
> get this error:
>
> Line: 11
> Char: 5
> Error: The directory property cannot be found in the cache.
> Code: 8000500D
> Source: Active Directory
>
> Which point to this line of code: objUser.AccountDisabled = FALSE  If I rem
> this out it creates the account but is disabled.
>
> Also is it possible to make the crated accounts members of the particular
> groups using the same script.
>
> Set objExcel = CreateObject("Excel.Application")
> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
> intRow = 2
> Do Until objExcel.Cells(intRow,1).Value = ""
> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
> 1).Value)
>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
>     objUser.SN = objExcel.Cells(intRow, 4).Value
>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
>     objUser.AccountDisabled = FALSE
>     objUser.SetInfo
>     intRow = intRow + 1
> Loop
> objExcel.Quit
>
>
>
Author
8 Feb 2006 8:03 PM
Lion
I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I don't
think profile line is the problem as I get same error when I take this line
out.

Thanks for your suggestion.



Show quoteHide quote
"Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
> When I was creating users using excel file, I encountered the same error.
> However, I strongly believe that this error is not caused by this line:
>
> objUser.AccountDisabled = FALSE
>
> You will get this error if you try to set any Terminal Server specific
> property
> and you are using Windows2000 server as DC. So, I suspect, this is caused
> by
> this line:
>
> objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
>
> try to comment this line, and execute the script. it should work fine.
>
> Windows 2000 server does not allow you to access Terminal Server specific
> properties using script, you MUST use WTS API to do that. tscmd.exe is a
> freeware tool that uses WTS API and allows you to modify user's terminal
> services specific properties.
>
>
> --
>
> "Lion" wrote:
>
>> Help please,
>>
>> I'm trying to put a script that will crate users from an Excel sheet and
>> I
>> get this error:
>>
>> Line: 11
>> Char: 5
>> Error: The directory property cannot be found in the cache.
>> Code: 8000500D
>> Source: Active Directory
>>
>> Which point to this line of code: objUser.AccountDisabled = FALSE  If I
>> rem
>> this out it creates the account but is disabled.
>>
>> Also is it possible to make the crated accounts members of the particular
>> groups using the same script.
>>
>> Set objExcel = CreateObject("Excel.Application")
>> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
>> intRow = 2
>> Do Until objExcel.Cells(intRow,1).Value = ""
>> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
>> 1).Value)
>>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
>>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
>>     objUser.SN = objExcel.Cells(intRow, 4).Value
>>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
>>     objUser.AccountDisabled = FALSE
>>     objUser.SetInfo
>>     intRow = intRow + 1
>> Loop
>> objExcel.Quit
>>
>>
>>
Author
8 Feb 2006 8:38 PM
Umesh Thakur
try using "objUser.SetInfo" before "objUser.AccountDisabled = FALSE" line.

as you cannot enable an account until it is created.
don't forget to use another "objUser.SetInfo" after the line:
"objUser.AccountDisabled = FALSE"

I checked it locally, and it worked for me.

--
When you are unable to keep your eyes open, do go and sleep for few hours!!!


Show quoteHide quote
"Lion" wrote:

> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I don't
> think profile line is the problem as I get same error when I take this line
> out.
>
> Thanks for your suggestion.
>
>
>
> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
> > When I was creating users using excel file, I encountered the same error.
> > However, I strongly believe that this error is not caused by this line:
> >
> > objUser.AccountDisabled = FALSE
> >
> > You will get this error if you try to set any Terminal Server specific
> > property
> > and you are using Windows2000 server as DC. So, I suspect, this is caused
> > by
> > this line:
> >
> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
> >
> > try to comment this line, and execute the script. it should work fine.
> >
> > Windows 2000 server does not allow you to access Terminal Server specific
> > properties using script, you MUST use WTS API to do that. tscmd.exe is a
> > freeware tool that uses WTS API and allows you to modify user's terminal
> > services specific properties.
> >
> >
> > --
> >
> > "Lion" wrote:
> >
> >> Help please,
> >>
> >> I'm trying to put a script that will crate users from an Excel sheet and
> >> I
> >> get this error:
> >>
> >> Line: 11
> >> Char: 5
> >> Error: The directory property cannot be found in the cache.
> >> Code: 8000500D
> >> Source: Active Directory
> >>
> >> Which point to this line of code: objUser.AccountDisabled = FALSE  If I
> >> rem
> >> this out it creates the account but is disabled.
> >>
> >> Also is it possible to make the crated accounts members of the particular
> >> groups using the same script.
> >>
> >> Set objExcel = CreateObject("Excel.Application")
> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
> >> intRow = 2
> >> Do Until objExcel.Cells(intRow,1).Value = ""
> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
> >>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
> >> 1).Value)
> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
> >>     objUser.AccountDisabled = FALSE
> >>     objUser.SetInfo
> >>     intRow = intRow + 1
> >> Loop
> >> objExcel.Quit
> >>
> >>
> >>
>
>
>
Author
8 Feb 2006 9:11 PM
J Ford
"TerminalServicesProfilePath" and other terminal server based properties are
only available if you are running on Server 2003, if you are trying to run
from Win2K or WinXP you will need a 3rd party util.

Like "wts_admin.dll" or "eolwtscom.dll"

ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
http://cwashington.netreach.net/main/tools/default.asp?topic=n-z






Show quoteHide quote
"Lion" wrote:

> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I don't
> think profile line is the problem as I get same error when I take this line
> out.
>
> Thanks for your suggestion.
>
>
>
> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
> > When I was creating users using excel file, I encountered the same error.
> > However, I strongly believe that this error is not caused by this line:
> >
> > objUser.AccountDisabled = FALSE
> >
> > You will get this error if you try to set any Terminal Server specific
> > property
> > and you are using Windows2000 server as DC. So, I suspect, this is caused
> > by
> > this line:
> >
> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
> >
> > try to comment this line, and execute the script. it should work fine.
> >
> > Windows 2000 server does not allow you to access Terminal Server specific
> > properties using script, you MUST use WTS API to do that. tscmd.exe is a
> > freeware tool that uses WTS API and allows you to modify user's terminal
> > services specific properties.
> >
> >
> > --
> >
> > "Lion" wrote:
> >
> >> Help please,
> >>
> >> I'm trying to put a script that will crate users from an Excel sheet and
> >> I
> >> get this error:
> >>
> >> Line: 11
> >> Char: 5
> >> Error: The directory property cannot be found in the cache.
> >> Code: 8000500D
> >> Source: Active Directory
> >>
> >> Which point to this line of code: objUser.AccountDisabled = FALSE  If I
> >> rem
> >> this out it creates the account but is disabled.
> >>
> >> Also is it possible to make the crated accounts members of the particular
> >> groups using the same script.
> >>
> >> Set objExcel = CreateObject("Excel.Application")
> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
> >> intRow = 2
> >> Do Until objExcel.Cells(intRow,1).Value = ""
> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
> >>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
> >> 1).Value)
> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
> >>     objUser.AccountDisabled = FALSE
> >>     objUser.SetInfo
> >>     intRow = intRow + 1
> >> Loop
> >> objExcel.Quit
> >>
> >>
> >>
>
>
>
Author
8 Feb 2006 9:38 PM
Lion
Yes got it working thanks to all!

Another question,

I want to create my users in the sub OU of Users called Finance Users, whot
would be the sintax to add that after Users

Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")




Show quoteHide quote
"J Ford" <JF***@discussions.microsoft.com> wrote in message
news:5E9258A9-B652-45CA-A918-F4DE9BA82D07@microsoft.com...
> "TerminalServicesProfilePath" and other terminal server based properties
> are
> only available if you are running on Server 2003, if you are trying to run
> from Win2K or WinXP you will need a 3rd party util.
>
> Like "wts_admin.dll" or "eolwtscom.dll"
>
> ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
> http://cwashington.netreach.net/main/tools/default.asp?topic=n-z
>
>
>
>
>
>
> "Lion" wrote:
>
>> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I don't
>> think profile line is the problem as I get same error when I take this
>> line
>> out.
>>
>> Thanks for your suggestion.
>>
>>
>>
>> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
>> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
>> > When I was creating users using excel file, I encountered the same
>> > error.
>> > However, I strongly believe that this error is not caused by this line:
>> >
>> > objUser.AccountDisabled = FALSE
>> >
>> > You will get this error if you try to set any Terminal Server specific
>> > property
>> > and you are using Windows2000 server as DC. So, I suspect, this is
>> > caused
>> > by
>> > this line:
>> >
>> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
>> >
>> > try to comment this line, and execute the script. it should work fine.
>> >
>> > Windows 2000 server does not allow you to access Terminal Server
>> > specific
>> > properties using script, you MUST use WTS API to do that. tscmd.exe is
>> > a
>> > freeware tool that uses WTS API and allows you to modify user's
>> > terminal
>> > services specific properties.
>> >
>> >
>> > --
>> >
>> > "Lion" wrote:
>> >
>> >> Help please,
>> >>
>> >> I'm trying to put a script that will crate users from an Excel sheet
>> >> and
>> >> I
>> >> get this error:
>> >>
>> >> Line: 11
>> >> Char: 5
>> >> Error: The directory property cannot be found in the cache.
>> >> Code: 8000500D
>> >> Source: Active Directory
>> >>
>> >> Which point to this line of code: objUser.AccountDisabled = FALSE  If
>> >> I
>> >> rem
>> >> this out it creates the account but is disabled.
>> >>
>> >> Also is it possible to make the crated accounts members of the
>> >> particular
>> >> groups using the same script.
>> >>
>> >> Set objExcel = CreateObject("Excel.Application")
>> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
>> >> intRow = 2
>> >> Do Until objExcel.Cells(intRow,1).Value = ""
>> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>> >>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
>> >> 1).Value)
>> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
>> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
>> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
>> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
>> >> 5).Value
>> >>     objUser.AccountDisabled = FALSE
>> >>     objUser.SetInfo
>> >>     intRow = intRow + 1
>> >> Loop
>> >> objExcel.Quit
>> >>
>> >>
>> >>
>>
>>
>>
Author
8 Feb 2006 9:54 PM
Lion
Got it worked out Im dumm tonight.
Show quoteHide quote
"Lion" <Lion@nospam.com> wrote in message
news:%23OOFlhPLGHA.1124@TK2MSFTNGP10.phx.gbl...
> Yes got it working thanks to all!
>
> Another question,
>
> I want to create my users in the sub OU of Users called Finance Users,
> whot would be the sintax to add that after Users
>
> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>
>
>
>
> "J Ford" <JF***@discussions.microsoft.com> wrote in message
> news:5E9258A9-B652-45CA-A918-F4DE9BA82D07@microsoft.com...
>> "TerminalServicesProfilePath" and other terminal server based properties
>> are
>> only available if you are running on Server 2003, if you are trying to
>> run
>> from Win2K or WinXP you will need a 3rd party util.
>>
>> Like "wts_admin.dll" or "eolwtscom.dll"
>>
>> ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
>> http://cwashington.netreach.net/main/tools/default.asp?topic=n-z
>>
>>
>>
>>
>>
>>
>> "Lion" wrote:
>>
>>> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I
>>> don't
>>> think profile line is the problem as I get same error when I take this
>>> line
>>> out.
>>>
>>> Thanks for your suggestion.
>>>
>>>
>>>
>>> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
>>> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
>>> > When I was creating users using excel file, I encountered the same
>>> > error.
>>> > However, I strongly believe that this error is not caused by this
>>> > line:
>>> >
>>> > objUser.AccountDisabled = FALSE
>>> >
>>> > You will get this error if you try to set any Terminal Server specific
>>> > property
>>> > and you are using Windows2000 server as DC. So, I suspect, this is
>>> > caused
>>> > by
>>> > this line:
>>> >
>>> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
>>> >
>>> > try to comment this line, and execute the script. it should work fine.
>>> >
>>> > Windows 2000 server does not allow you to access Terminal Server
>>> > specific
>>> > properties using script, you MUST use WTS API to do that. tscmd.exe is
>>> > a
>>> > freeware tool that uses WTS API and allows you to modify user's
>>> > terminal
>>> > services specific properties.
>>> >
>>> >
>>> > --
>>> >
>>> > "Lion" wrote:
>>> >
>>> >> Help please,
>>> >>
>>> >> I'm trying to put a script that will crate users from an Excel sheet
>>> >> and
>>> >> I
>>> >> get this error:
>>> >>
>>> >> Line: 11
>>> >> Char: 5
>>> >> Error: The directory property cannot be found in the cache.
>>> >> Code: 8000500D
>>> >> Source: Active Directory
>>> >>
>>> >> Which point to this line of code: objUser.AccountDisabled = FALSE  If
>>> >> I
>>> >> rem
>>> >> this out it creates the account but is disabled.
>>> >>
>>> >> Also is it possible to make the crated accounts members of the
>>> >> particular
>>> >> groups using the same script.
>>> >>
>>> >> Set objExcel = CreateObject("Excel.Application")
>>> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
>>> >> intRow = 2
>>> >> Do Until objExcel.Cells(intRow,1).Value = ""
>>> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>>> >>     Set objUser = objOU.Create ("User", "cn=" &
>>> >> objExcel.Cells(intRow,
>>> >> 1).Value)
>>> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
>>> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
>>> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
>>> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
>>> >> 5).Value
>>> >>     objUser.AccountDisabled = FALSE
>>> >>     objUser.SetInfo
>>> >>     intRow = intRow + 1
>>> >> Loop
>>> >> objExcel.Quit
>>> >>
>>> >>
>>> >>
>>>
>>>
>>>
>
>
Author
8 Feb 2006 10:21 PM
Umesh Thakur
It should be:

Set objOU = GetObject("LDAP://OU=Finance Users,CN=Users, dc=Domain, dc=com,
dc=local")

if it does not work, you will need to find DN of the "Finance Users" OU...

use following command to get full DN of "Finance Users" OU:

dsquery * -filter "&(ObjectCategory=OrganizationalUnit)(name=Finance Users)"
-scope base -attr distinguishedName

this will return DN of "Finance Users" OU. you can copy pate it to use as:
Set objOU = GetObject("LDAP://" & "paste here")

--
"C is a razor-sharp tool, with which one can create an elegant and efficient
program or a bloody mess."
Replace C with VBScript :)



Show quoteHide quote
"Lion" wrote:

> Yes got it working thanks to all!
>
> Another question,
>
> I want to create my users in the sub OU of Users called Finance Users, whot
> would be the sintax to add that after Users
>
> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>
>
>
>
> "J Ford" <JF***@discussions.microsoft.com> wrote in message
> news:5E9258A9-B652-45CA-A918-F4DE9BA82D07@microsoft.com...
> > "TerminalServicesProfilePath" and other terminal server based properties
> > are
> > only available if you are running on Server 2003, if you are trying to run
> > from Win2K or WinXP you will need a 3rd party util.
> >
> > Like "wts_admin.dll" or "eolwtscom.dll"
> >
> > ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
> > http://cwashington.netreach.net/main/tools/default.asp?topic=n-z
> >
> >
> >
> >
> >
> >
> > "Lion" wrote:
> >
> >> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I don't
> >> think profile line is the problem as I get same error when I take this
> >> line
> >> out.
> >>
> >> Thanks for your suggestion.
> >>
> >>
> >>
> >> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
> >> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
> >> > When I was creating users using excel file, I encountered the same
> >> > error.
> >> > However, I strongly believe that this error is not caused by this line:
> >> >
> >> > objUser.AccountDisabled = FALSE
> >> >
> >> > You will get this error if you try to set any Terminal Server specific
> >> > property
> >> > and you are using Windows2000 server as DC. So, I suspect, this is
> >> > caused
> >> > by
> >> > this line:
> >> >
> >> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow, 5).Value
> >> >
> >> > try to comment this line, and execute the script. it should work fine.
> >> >
> >> > Windows 2000 server does not allow you to access Terminal Server
> >> > specific
> >> > properties using script, you MUST use WTS API to do that. tscmd.exe is
> >> > a
> >> > freeware tool that uses WTS API and allows you to modify user's
> >> > terminal
> >> > services specific properties.
> >> >
> >> >
> >> > --
> >> >
> >> > "Lion" wrote:
> >> >
> >> >> Help please,
> >> >>
> >> >> I'm trying to put a script that will crate users from an Excel sheet
> >> >> and
> >> >> I
> >> >> get this error:
> >> >>
> >> >> Line: 11
> >> >> Char: 5
> >> >> Error: The directory property cannot be found in the cache.
> >> >> Code: 8000500D
> >> >> Source: Active Directory
> >> >>
> >> >> Which point to this line of code: objUser.AccountDisabled = FALSE  If
> >> >> I
> >> >> rem
> >> >> this out it creates the account but is disabled.
> >> >>
> >> >> Also is it possible to make the crated accounts members of the
> >> >> particular
> >> >> groups using the same script.
> >> >>
> >> >> Set objExcel = CreateObject("Excel.Application")
> >> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
> >> >> intRow = 2
> >> >> Do Until objExcel.Cells(intRow,1).Value = ""
> >> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
> >> >>     Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells(intRow,
> >> >> 1).Value)
> >> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
> >> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
> >> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
> >> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
> >> >> 5).Value
> >> >>     objUser.AccountDisabled = FALSE
> >> >>     objUser.SetInfo
> >> >>     intRow = intRow + 1
> >> >> Loop
> >> >> objExcel.Quit
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Author
8 Feb 2006 10:47 PM
Lion
The script is now working,  where in the script should I put the folowing to
add the groups to newly creted accounts please.

' Group DN's start in column 11.
      intCol = 11
      Do While objSheet.Cells(intRow, intCol).Value <> ""
        strGroupDN = Trim(objSheet.Cells(intRow, intCol).Value)
        On Error Resume Next
        Set objGroup = GetObject("LDAP://" & strGroupDN)
        If Err.Number <> 0 Then
          On Error GoTo 0
          Wscript.Echo "Unable to bind to group " & strGroupDN
        Else
          objGroup.Add objUser.AdsPath
          If Err.Number <> 0 Then
            On Error GoTo 0
            Wscript.Echo "Unable to add user " & strNTName _
              & " to group " & strGroupDN
          End If
        End If
        On Error GoTo 0
        ' Increment to next group DN.
        intCol = intCol + 1
      Loop
    End If
  End If


********Working script below*****************

Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD, strTSProfile


strOU = "OU=Users,OU=Laptop Users ,"
strSheet = "C:\Scripts\Users.xls"

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU &
objRootLDAP.Get("defaultNamingContext"))

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 2 'Row 1 often contains headings

' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
   strSam = Trim(objExcel.Cells(intRow, 1).Value)
   strCN = Trim(objExcel.Cells(intRow, 2).Value)
   strFirst = Trim(objExcel.Cells(intRow, 3).Value)
   strLast = Trim(objExcel.Cells(intRow, 4).Value)
   strPWD = Trim(objExcel.Cells(intRow, 5).Value)
   strTSProfile = Trim(objExcel.Cells(intRow, 6).Value)


   ' Build the actual User from data in strSheet.
   Set objUser = objContainer.Create("User", "cn=" & strCN)
   objUser.sAMAccountName = strSam
   objUser.givenName = strFirst
   objUser.sn = strLast
   objUser.TerminalServicesProfilePath = strTSProfile
   objUser.SetInfo

   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.pwdLastSet = 0
   objUser.SetPassword strPWD
   objUser.SetInfo

intRow = intRow + 1
Loop
objExcel.Quit

WScript.Quit

' End of Sample UserSpreadsheet VBScript.







Show quoteHide quote
"Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
news:A56EEC32-B33A-4FD1-B7C9-5E91D5E0C460@microsoft.com...
> It should be:
>
> Set objOU = GetObject("LDAP://OU=Finance Users,CN=Users, dc=Domain,
> dc=com,
> dc=local")
>
> if it does not work, you will need to find DN of the "Finance Users" OU...
>
> use following command to get full DN of "Finance Users" OU:
>
> dsquery * -filter "&(ObjectCategory=OrganizationalUnit)(name=Finance
> Users)"
> -scope base -attr distinguishedName
>
> this will return DN of "Finance Users" OU. you can copy pate it to use as:
> Set objOU = GetObject("LDAP://" & "paste here")
>
> --
> "C is a razor-sharp tool, with which one can create an elegant and
> efficient
> program or a bloody mess."
> Replace C with VBScript :)
>
>
>
> "Lion" wrote:
>
>> Yes got it working thanks to all!
>>
>> Another question,
>>
>> I want to create my users in the sub OU of Users called Finance Users,
>> whot
>> would be the sintax to add that after Users
>>
>> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
>>
>>
>>
>>
>> "J Ford" <JF***@discussions.microsoft.com> wrote in message
>> news:5E9258A9-B652-45CA-A918-F4DE9BA82D07@microsoft.com...
>> > "TerminalServicesProfilePath" and other terminal server based
>> > properties
>> > are
>> > only available if you are running on Server 2003, if you are trying to
>> > run
>> > from Win2K or WinXP you will need a 3rd party util.
>> >
>> > Like "wts_admin.dll" or "eolwtscom.dll"
>> >
>> > ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
>> > http://cwashington.netreach.net/main/tools/default.asp?topic=n-z
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Lion" wrote:
>> >
>> >> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I
>> >> don't
>> >> think profile line is the problem as I get same error when I take this
>> >> line
>> >> out.
>> >>
>> >> Thanks for your suggestion.
>> >>
>> >>
>> >>
>> >> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in
>> >> message
>> >> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
>> >> > When I was creating users using excel file, I encountered the same
>> >> > error.
>> >> > However, I strongly believe that this error is not caused by this
>> >> > line:
>> >> >
>> >> > objUser.AccountDisabled = FALSE
>> >> >
>> >> > You will get this error if you try to set any Terminal Server
>> >> > specific
>> >> > property
>> >> > and you are using Windows2000 server as DC. So, I suspect, this is
>> >> > caused
>> >> > by
>> >> > this line:
>> >> >
>> >> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
>> >> > 5).Value
>> >> >
>> >> > try to comment this line, and execute the script. it should work
>> >> > fine.
>> >> >
>> >> > Windows 2000 server does not allow you to access Terminal Server
>> >> > specific
>> >> > properties using script, you MUST use WTS API to do that. tscmd.exe
>> >> > is
>> >> > a
>> >> > freeware tool that uses WTS API and allows you to modify user's
>> >> > terminal
>> >> > services specific properties.
>> >> >
>> >> >
>> >> > --
>> >> >
>> >> > "Lion" wrote:
>> >> >
>> >> >> Help please,
>> >> >>
>> >> >> I'm trying to put a script that will crate users from an Excel
>> >> >> sheet
>> >> >> and
>> >> >> I
>> >> >> get this error:
>> >> >>
>> >> >> Line: 11
>> >> >> Char: 5
>> >> >> Error: The directory property cannot be found in the cache.
>> >> >> Code: 8000500D
>> >> >> Source: Active Directory
>> >> >>
>> >> >> Which point to this line of code: objUser.AccountDisabled = FALSE
>> >> >> If
>> >> >> I
>> >> >> rem
>> >> >> this out it creates the account but is disabled.
>> >> >>
>> >> >> Also is it possible to make the crated accounts members of the
>> >> >> particular
>> >> >> groups using the same script.
>> >> >>
>> >> >> Set objExcel = CreateObject("Excel.Application")
>> >> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
>> >> >> intRow = 2
>> >> >> Do Until objExcel.Cells(intRow,1).Value = ""
>> >> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com,
>> >> >> dc=local")
>> >> >>     Set objUser = objOU.Create ("User", "cn=" &
>> >> >> objExcel.Cells(intRow,
>> >> >> 1).Value)
>> >> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
>> >> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
>> >> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
>> >> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
>> >> >> 5).Value
>> >> >>     objUser.AccountDisabled = FALSE
>> >> >>     objUser.SetInfo
>> >> >>     intRow = intRow + 1
>> >> >> Loop
>> >> >> objExcel.Quit
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>
Author
9 Feb 2006 12:08 AM
Umesh Thakur
'Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo

'=============================================
ADD YOUR CODE BLOCK TO ADD USER TO GROUPS HERE
'=============================================

intRow = intRow + 1
Loop
objExcel.Quit

--
"C is a razor-sharp tool, with which one can create an elegant and efficient
program or a bloody mess."
Replace C with VBScript :)



Show quoteHide quote
"Lion" wrote:

> The script is now working,  where in the script should I put the folowing to
> add the groups to newly creted accounts please.
>
> ' Group DN's start in column 11.
>       intCol = 11
>       Do While objSheet.Cells(intRow, intCol).Value <> ""
>         strGroupDN = Trim(objSheet.Cells(intRow, intCol).Value)
>         On Error Resume Next
>         Set objGroup = GetObject("LDAP://" & strGroupDN)
>         If Err.Number <> 0 Then
>           On Error GoTo 0
>           Wscript.Echo "Unable to bind to group " & strGroupDN
>         Else
>           objGroup.Add objUser.AdsPath
>           If Err.Number <> 0 Then
>             On Error GoTo 0
>             Wscript.Echo "Unable to add user " & strNTName _
>               & " to group " & strGroupDN
>           End If
>         End If
>         On Error GoTo 0
>         ' Increment to next group DN.
>         intCol = intCol + 1
>       Loop
>     End If
>   End If
>
>
> ********Working script below*****************
>
> Option Explicit
> Dim objRootLDAP, objContainer, objUser, objShell
> Dim objExcel, objSpread, intRow
> Dim strUser, strOU, strSheet
> Dim strCN, strSam, strFirst, strLast, strPWD, strTSProfile
>
>
> strOU = "OU=Users,OU=Laptop Users ,"
> strSheet = "C:\Scripts\Users.xls"
>
> ' Bind to Active Directory, Users container.
> Set objRootLDAP = GetObject("LDAP://rootDSE")
> Set objContainer = GetObject("LDAP://" & strOU &
> objRootLDAP.Get("defaultNamingContext"))
>
> ' Open the Excel spreadsheet
> Set objExcel = CreateObject("Excel.Application")
> Set objSpread = objExcel.Workbooks.Open(strSheet)
> intRow = 2 'Row 1 often contains headings
>
> ' Here is the 'DO...Loop' that cycles through the cells
> ' Note intRow, x must correspond to the column in strSheet
> Do Until objExcel.Cells(intRow,1).Value = ""
>    strSam = Trim(objExcel.Cells(intRow, 1).Value)
>    strCN = Trim(objExcel.Cells(intRow, 2).Value)
>    strFirst = Trim(objExcel.Cells(intRow, 3).Value)
>    strLast = Trim(objExcel.Cells(intRow, 4).Value)
>    strPWD = Trim(objExcel.Cells(intRow, 5).Value)
>    strTSProfile = Trim(objExcel.Cells(intRow, 6).Value)
>
>
>    ' Build the actual User from data in strSheet.
>    Set objUser = objContainer.Create("User", "cn=" & strCN)
>    objUser.sAMAccountName = strSam
>    objUser.givenName = strFirst
>    objUser.sn = strLast
>    objUser.TerminalServicesProfilePath = strTSProfile
>    objUser.SetInfo
>
>    ' Separate section to enable account with its password
>    objUser.userAccountControl = 512
>    objUser.pwdLastSet = 0
>    objUser.SetPassword strPWD
>    objUser.SetInfo
>
> intRow = intRow + 1
> Loop
> objExcel.Quit
>
> WScript.Quit
>
> ' End of Sample UserSpreadsheet VBScript.
>
>
>
>
>
>
>
> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in message
> news:A56EEC32-B33A-4FD1-B7C9-5E91D5E0C460@microsoft.com...
> > It should be:
> >
> > Set objOU = GetObject("LDAP://OU=Finance Users,CN=Users, dc=Domain,
> > dc=com,
> > dc=local")
> >
> > if it does not work, you will need to find DN of the "Finance Users" OU...
> >
> > use following command to get full DN of "Finance Users" OU:
> >
> > dsquery * -filter "&(ObjectCategory=OrganizationalUnit)(name=Finance
> > Users)"
> > -scope base -attr distinguishedName
> >
> > this will return DN of "Finance Users" OU. you can copy pate it to use as:
> > Set objOU = GetObject("LDAP://" & "paste here")
> >
> > --
> > "C is a razor-sharp tool, with which one can create an elegant and
> > efficient
> > program or a bloody mess."
> > Replace C with VBScript :)
> >
> >
> >
> > "Lion" wrote:
> >
> >> Yes got it working thanks to all!
> >>
> >> Another question,
> >>
> >> I want to create my users in the sub OU of Users called Finance Users,
> >> whot
> >> would be the sintax to add that after Users
> >>
> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com, dc=local")
> >>
> >>
> >>
> >>
> >> "J Ford" <JF***@discussions.microsoft.com> wrote in message
> >> news:5E9258A9-B652-45CA-A918-F4DE9BA82D07@microsoft.com...
> >> > "TerminalServicesProfilePath" and other terminal server based
> >> > properties
> >> > are
> >> > only available if you are running on Server 2003, if you are trying to
> >> > run
> >> > from Win2K or WinXP you will need a 3rd party util.
> >> >
> >> > Like "wts_admin.dll" or "eolwtscom.dll"
> >> >
> >> > ftp://ftp.go-eol.com/PUBLIC/THINSSENTIALS/wtscom/
> >> > http://cwashington.netreach.net/main/tools/default.asp?topic=n-z
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Lion" wrote:
> >> >
> >> >> I'm running a native 2003 mode, my DC's are 2003 Ent Edition SP1. I
> >> >> don't
> >> >> think profile line is the problem as I get same error when I take this
> >> >> line
> >> >> out.
> >> >>
> >> >> Thanks for your suggestion.
> >> >>
> >> >>
> >> >>
> >> >> "Umesh Thakur" <UmeshTha***@discussions.microsoft.com> wrote in
> >> >> message
> >> >> news:E074DB36-E71B-4ABB-94F2-A1E51C151FF2@microsoft.com...
> >> >> > When I was creating users using excel file, I encountered the same
> >> >> > error.
> >> >> > However, I strongly believe that this error is not caused by this
> >> >> > line:
> >> >> >
> >> >> > objUser.AccountDisabled = FALSE
> >> >> >
> >> >> > You will get this error if you try to set any Terminal Server
> >> >> > specific
> >> >> > property
> >> >> > and you are using Windows2000 server as DC. So, I suspect, this is
> >> >> > caused
> >> >> > by
> >> >> > this line:
> >> >> >
> >> >> > objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
> >> >> > 5).Value
> >> >> >
> >> >> > try to comment this line, and execute the script. it should work
> >> >> > fine.
> >> >> >
> >> >> > Windows 2000 server does not allow you to access Terminal Server
> >> >> > specific
> >> >> > properties using script, you MUST use WTS API to do that. tscmd.exe
> >> >> > is
> >> >> > a
> >> >> > freeware tool that uses WTS API and allows you to modify user's
> >> >> > terminal
> >> >> > services specific properties.
> >> >> >
> >> >> >
> >> >> > --
> >> >> >
> >> >> > "Lion" wrote:
> >> >> >
> >> >> >> Help please,
> >> >> >>
> >> >> >> I'm trying to put a script that will crate users from an Excel
> >> >> >> sheet
> >> >> >> and
> >> >> >> I
> >> >> >> get this error:
> >> >> >>
> >> >> >> Line: 11
> >> >> >> Char: 5
> >> >> >> Error: The directory property cannot be found in the cache.
> >> >> >> Code: 8000500D
> >> >> >> Source: Active Directory
> >> >> >>
> >> >> >> Which point to this line of code: objUser.AccountDisabled = FALSE
> >> >> >> If
> >> >> >> I
> >> >> >> rem
> >> >> >> this out it creates the account but is disabled.
> >> >> >>
> >> >> >> Also is it possible to make the crated accounts members of the
> >> >> >> particular
> >> >> >> groups using the same script.
> >> >> >>
> >> >> >> Set objExcel = CreateObject("Excel.Application")
> >> >> >> Set objWorkbook = objExcel.Workbooks.Open ("C:\Scripts\Test.xls")
> >> >> >> intRow = 2
> >> >> >> Do Until objExcel.Cells(intRow,1).Value = ""
> >> >> >> Set objOU = GetObject("LDAP://OU=Users, dc=Domain, dc=com,
> >> >> >> dc=local")
> >> >> >>     Set objUser = objOU.Create ("User", "cn=" &
> >> >> >> objExcel.Cells(intRow,
> >> >> >> 1).Value)
> >> >> >>     objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
> >> >> >>     objUser.GivenName = objExcel.Cells(intRow, 3).Value
> >> >> >>     objUser.SN = objExcel.Cells(intRow, 4).Value
> >> >> >>     objUser.TerminalServicesProfilePath = objExcel.Cells(intRow,
> >> >> >> 5).Value
> >> >> >>     objUser.AccountDisabled = FALSE
> >> >> >>     objUser.SetInfo
> >> >> >>     intRow = intRow + 1
> >> >> >> Loop
> >> >> >> objExcel.Quit
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>