JJscorpio
(Fresh Scripter)
2002-09-16 11:51 PM
Where are my Values? need help!

I am trying to automate my callcenter user builds. We have 2 or 3 classes a week of 15 - 20 agents. I read from an excel file (Thanks Kynder [Cool] ) the user ID, full name, description , password, logon script and dept. (which I'll use to assign groups if I can get this working) I get the user account built ok, but none of the other values for name, description etc are working. If the user ID is 9999 I'll get an account 9999 with full name as 9999 and no other info... I have checked my values using ? $value1 ? and all come out ok!
Help! [Confused] [Confused] [Confused]

code:
 Break ON

CLS

$Class = "C:\training\current_build.xls"
ReadData($Class)
? "ID's Have Been Successfully Created"

Function ReadData($Class)
$object = CreateObject("Excel.Application")
If $Class = ""
? "Class File not found"
? "The Excel File "+$Class+" Must exist before ID Build is run"
Goto Clear
EndIf
; Open Workbook
$_=$object.workbooks.Open ($Class)
$Cell = 2 ;Set start value, Row one and two are column and group Headings

$x = $object.cells($Cell, 1).value

While $object.cells($Cell, 1).value <> ""
$Cell = $Cell + 1
If $object.cells($Cell, 1).value = ""
Goto Clear

EndIf

$value1 = $object.cells($Cell, 1).value

$value2 = $object.cells($Cell, 2).value

$value3 = $object.cells($Cell, 3).value

$value4 = $object.cells($Cell, 4).value

$value5 = $object.cells($Cell, 5).value

CreateUser ($Value1, "CCC")

Loop
:clear
$object.application.Quit
$object = ""
EndFunction


Function CreateUser ($XName, $XDomain)

? "Creating Account..."

$UserName = $Value1
$DomainName = "CCC"

;Create the objects Domain and User.

$Domain = GetObject("WinNT://" + $DomainName + ",domain")
$User = $Domain.Create("user", $UserName)

;Set user account flags.

$User.FullName = $Value2
$User.Description = $Value3
$User.SetPassword = $Value4
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo


;Cleanup Objects Domain and User

Set $User = 0
Set $Domain = 0
Set $UserName = 0
Set $DomainName = 0
? "ID complete"
EndFunction



Sealeopard
(KiX Master)
2002-09-17 12:21 AM
Re: Where are my Values? need help!

You're not passing the values into the CreateUser function, only $value1, and your not making use of $XDomain either.

[ 17. September 2002, 00:21: Message edited by: sealeopard ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 12:32 AM
Re: Where are my Values? need help!

well, he is not passing anything there...
in sense that he passes only the required fields but does not use them.

in this way of thinking, he populates the vars alright, but there is something else...


JJscorpio
(Fresh Scripter)
2002-09-17 01:22 PM
Re: Where are my Values? need help!

I used Xname and Xdomain because they were required, but I did not need them (or so I thought) because I read/set the vars I want to use in another function. I am still pretty new at this so my code is prob not very efficent. Is there a better or more standard way? (obviously better as mine doesn't work...) [Big Grin]

JochenAdministrator
(KiX Supporter)
2002-09-17 02:00 PM
Re: Where are my Values? need help!

Well,

you could make it work by passing $value2 through $value4 as function arguments to CreatUser()

right ?

J.


JochenAdministrator
(KiX Supporter)
2002-09-17 02:02 PM
Re: Where are my Values? need help!

Plus ,

just noticed that you use invalid code :

replace

set $var = 0

by

$var = 0


JochenAdministrator
(KiX Supporter)
2002-09-17 02:10 PM
Re: Where are my Values? need help!

Try these ammendments :

call CreateUser() as this :

code:
$ = CreateUser ($Value1, $Value2, $Value3, $Value4)

CreateUser() should look like this (No error checking / untested)

code:
Function CreateUser ($Name, $FullName, $Desc, $pwd)

? "Creating Account..." ;don't know how this looks , but think it gets better commented out :D

;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)

;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo

;Cleanup Objects Domain and User
$Domain = 0
$user = 0

? "ID complete"
EndFunction

hth

Jochen

[ 17. September 2002, 14:13: Message edited by: jpols ]


JJscorpio
(Fresh Scripter)
2002-09-17 02:34 PM
Re: Where are my Values? need help!

jpols,
Thanks for helping! [Cool]
I fixed the set statements. I also tried the script changes... I get the same results. They values for $value1 $value2 ... $value5 all display the correct values when printed to screen but when the create user function executes (your way is so much cleaner) I only get user 9999 ($vaule1) and fullname 9999 ($value1... should be $vaule2) and nothing else, no logon.bat, no description [Frown]
I'm still stumped


JochenAdministrator
(KiX Supporter)
2002-09-17 02:38 PM
Re: Where are my Values? need help!

JJ,

can you please give a sample of how your Excel table looks ? I will then try to re-write that part [Wink]


JJscorpio
(Fresh Scripter)
2002-09-17 02:46 PM
Re: Where are my Values? need help!

jpols,
Sure! rows 1 and 2 are headers row 3 is where data starts:
3a is "9999" agent ID (I am testing with 9999)
3b is "Lastname, First"
3c is "Representative (group), x9999" (description in the format we use)
3d is "password" (default password will be randomly assigned to each class)
3e "dept" (is the dept the will be a mamber of)

Then the next user would start on row 4 repeat.

I hope to use 3e later to assign the user, once created, to groups.

Thanks again for your time. [Smile]


JochenAdministrator
(KiX Supporter)
2002-09-17 02:48 PM
Re: Where are my Values? need help!

K,

give me some minutes

l8r


JJscorpio
(Fresh Scripter)
2002-09-17 02:51 PM
Re: Where are my Values? need help!

The thing that I just don't get is if I ? $value1 ? for all the values after reading from excel I get the correct values for each var... $value1 is the ID "9999" $value2 is the full name "lastname, first" $value3 is the description... but when I try to pass them to createuser something breaks.

JochenAdministrator
(KiX Supporter)
2002-09-17 03:42 PM
Re: Where are my Values? need help!

Ok,

I see ... try this one (Made sure that all variables are passed to CreateUser()) :

code:
break on cls

$Class = "C:\training\current_build.xls"

$ = ReadData($Class)

? "ID's Have Been Successfully Created"


exit 1


Function ReadData($Class)
If not exist($Class)
? "Class File not found"
? "The Excel File " + $Class + " Must exist before ID Build is run"
exit ()
EndIf
$xl = CreateObject("Excel.Application")

; Open Workbook

$ = $xl.Workbooks.Open($Class)
$Cell = 3 ;Set start value, Row one and two are column and group Headings

while $xl.Range("A"+$Cell+"").value

$value1 = $xl.Range("A"+$Cell+"").value

$value2 = $xl.Range("B"+$Cell+"").value

$value3 = $xl.Range("C"+$Cell+"").value

$value4 = $xl.Range("D"+$Cell+"").value

$value5 = $xl.Range("E"+$Cell+"").value

$ = CreateUser ($Value1, $Value2, $Value3, $Value4, $Value5)

$Cell = $Cell + 1
loop
$xl.UserControl = 1
$ = $xl.Quit
$xl = ""
endfunction


Function CreateUser ($Name, $FullName, $Desc, $pwd, $Group)

? "Creating Account..."
;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)

;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)
;add the user to group here !

$User.SetInfo

;Cleanup Objects Domain and User
$Domain = 0
$user = 0

? "ID complete"
EndFunction



JochenAdministrator
(KiX Supporter)
2002-09-17 03:51 PM
Re: Where are my Values? need help!

By the way ,

here a version that should (?) add the user to a group :

code:
break on cls

$Class = "C:\training\current_build.xls"

$ = ReadData($Class)

? "ID's Have Been Successfully Created"


exit 1


Function ReadData($Class)
If not exist($Class)
? "Class File not found"
? "The Excel File " + $Class + " Must exist before ID Build is run"
exit ()
EndIf
$xl = CreateObject("Excel.Application")

; Open Workbook

$ = $xl.Workbooks.Open($Class)
$Cell = 3 ;Set start value, Row one and two are column and group Headings

while $xl.Range("A"+$Cell+"").value

$value1 = $xl.Range("A"+$Cell+"").value

$value2 = $xl.Range("B"+$Cell+"").value

$value3 = $xl.Range("C"+$Cell+"").value

$value4 = $xl.Range("D"+$Cell+"").value

$value5 = $xl.Range("E"+$Cell+"").value

$ = CreateUser ($Value1, $Value2, $Value3, $Value4, $Value5)

$Cell = $Cell + 1
loop
$xl.UserControl = 1
$ = $xl.Quit
$xl = ""
endfunction


Function CreateUser ($Name, $FullName, $Desc, $pwd, $Group)

? "Creating Account..."
;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)
$GroupObj = GetObject("WinNT://CCC/$Group")
;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo

$groupObj.Add ("WinNT://CCC/$Name")


;Cleanup Objects Domain and User
$Domain = 0
$user = 0
$groupObj = 0

? "ID complete"
EndFunction

Totally untested [Razz]

J.

[ 17. September 2002, 16:31: Message edited by: jpols ]


JJscorpio
(Fresh Scripter)
2002-09-17 05:15 PM
Re: Where are my Values? need help!

Jpols,
...sigh I ran your script and I get the same result. user 9999 named 9999 and no other values. I checked the var in your script and just like the ones in mine they display correctly but do not seem to write to createuser() correctly. Back to square one. Thank you, I have learned several things from your help! [Smile]

[ 17. September 2002, 17:34: Message edited by: JJscorpio ]


JJscorpio
(Fresh Scripter)
2002-09-17 07:59 PM
Re: Where are my Values? need help!

I know this post is getting long... I am running Kixtart 4.11. PDC is an NT 4.0 server. I have been runnig this from a W2K workstation (maybe a problem?) I tried it from an NT 4.0 (sp 6a) pc and gett an error---
Script error: expected expression:
$User = $Domain.Create("user", $UserName)

I usually get this when my vars are not consistant... but I am not seeing the problem here.

<<< Doh >>> I know why the NT pc gets the error... It doesn't have the WMI dependencies.
My initial problem stands

[ 18. September 2002, 00:01: Message edited by: JJscorpio ]


JochenAdministrator
(KiX Supporter)
2002-09-19 09:23 AM
Re: Where are my Values? need help!

Hmmm ,

I think the problem is not the pass of variables to CreateUser() but the ADSI function calls ... Unable to test right now , Anyone else ?

J.


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 09:27 AM
Re: Where are my Values? need help!

jpols good notice...
like I said in the first reply, the problem is elsewhere.

he does not need to pass the vars as they are global.


JochenAdministrator
(KiX Supporter)
2002-09-19 09:28 AM
Re: Where are my Values? need help!

Ok,

seems to be that Howard solved your problem !

For all interested : you can find this here

J.


NTDOCAdministrator
(KiX Master)
2002-09-19 09:48 AM
Re: Where are my Values? need help!

Well,
I have a question I don't see asked or answered here.

Are you trying to add accounts to NT or AD?

Maybe try taking a look at this post as well for AD.

Enumerate User Info with ADSI


JJscorpio
(Fresh Scripter)
2002-09-19 06:00 PM
Re: Where are my Values? need help!

Doc,
I am building NT users. I cleaned up my script with jpols help, I also got some help from Howard in another post (thought this post was dead, sorry) I found my problem was with $user.setpassword = $value4 changed it to $user.setpassword = "password" and everything worked. final (much cleaner thanks to jopls [Smile] ) code below:

code:
Break ON

CLS

$Class = "C:\training\current_build.xls"
ReadData($Class)
? "ID's Have Been Successfully Created"

Function ReadData($Class)
$object = CreateObject("Excel.Application")
If $Class = ""
? "Class File not found"
? "The Excel File "+$Class+" Must exist before ID Build is run"
Goto Clear
EndIf
; Open Workbook
$_=$object.workbooks.Open ($Class)
$Cell = 2 ;Set start value, Row one and two are column and group Headings

$x = $object.cells($Cell, 1).value

While $object.cells($Cell, 1).value <> ""
$Cell = $Cell + 1
If $object.cells($Cell, 1).value = ""
Goto Clear

EndIf

$value1 = $object.cells($Cell, 1).value
? $value1
$value2 = $object.cells($Cell, 2).value
? $value2
$value3 = $object.cells($Cell, 3).value
? $value3
$value4 = $object.cells($Cell, 4).value
? $value4
$value5 = $object.cells($Cell, 5).value
? $value5
CreateUser ($Value1, $value2, $value3, $value5)

Loop
:clear
$object.application.Quit
$object = ""
EndFunction


Function CreateUser ($UserName, $FullName, $Desc, $group)

? "Creating Account..."
;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
? "Domain: @error @serror"
$User = $Domain.Create("user", $UserName)
? "User: @error @serror"
? "User: @error @serror"

$User.SetInfo

$User.GetInfo

$User.fullName = $FullName
? "Fullname: @error @serror"
$User.description = $Desc
? "description: @error @serror"
$User.SetPassword = ("password")
? "SetPwd: @ERROR @SERROR"
$User.LoginScript = "logon.bat"
? "logon: @error @serror"
$User.Put ("PasswordExpired", 1)
? "Password Exp: @error @serror"

$User.SetInfo

;Cleanup Objects Domain and User

$User = 0
$Domain = 0
? "ID complete"
EndFunction