#87992 - 2002-09-16 11:51 PM
Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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 ) 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!
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
|
Top
|
|
|
|
#87995 - 2002-09-17 01:22 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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...)
|
Top
|
|
|
|
#87998 - 2002-09-17 02:10 PM
Re: Where are my Values? need help!
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
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 ]
_________________________
|
Top
|
|
|
|
#87999 - 2002-09-17 02:34 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
jpols, Thanks for helping! 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 I'm still stumped
|
Top
|
|
|
|
#88001 - 2002-09-17 02:46 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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.
|
Top
|
|
|
|
#88003 - 2002-09-17 02:51 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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.
|
Top
|
|
|
|
#88004 - 2002-09-17 03:42 PM
Re: Where are my Values? need help!
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
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
_________________________
|
Top
|
|
|
|
#88005 - 2002-09-17 03:51 PM
Re: Where are my Values? need help!
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
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
J. [ 17. September 2002, 16:31: Message edited by: jpols ]
_________________________
|
Top
|
|
|
|
#88006 - 2002-09-17 05:15 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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! [ 17. September 2002, 17:34: Message edited by: JJscorpio ]
|
Top
|
|
|
|
#88007 - 2002-09-17 07:59 PM
Re: Where are my Values? need help!
|
JJscorpio
Fresh Scripter
Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
|
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 ]
|
Top
|
|
|
|
#88011 - 2002-09-19 09:48 AM
Re: Where are my Values? need help!
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
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
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 464 anonymous users online.
|
|
|