• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

Script to Create Multiple Local User accounts from spread sheet

Does anyone have a script that will create multipe local (not AD) user accounts with passwords from information stored in an excel spread sheet?
0
kjudy408
Asked:
kjudy408
  • 7
  • 6
1 Solution
 
yehudahaCommented:
how the information in the exel file looks ?

any example will help
0
 
kjudy408Author Commented:
2 columns one labeled username the other labled password
Username      Password
user1            password1
0
 
yehudahaCommented:
change this line to your excel file name and path

strXlsPath = "C:\test\users.xls"

the script will affect the local computer you running the script but if you want to run it against remote computer just change this line :

strComputer = "."

example:

strComputer = "server23"


strComputer = "."
strXlsPath = "C:\test\users.xls"
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    (strXlsPath)
 
intRow1 = 1
intRow2 = 1
 
Do Until objExcel.Cells(intRow1,1).Value = "" Or objExcel.Cells(intRow2,1).Value = ""
strUser = objExcel.Cells(intRow1,1).Value
strPassword = objExcel.Cells(intRow2,2).Value
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", strUser)
objUser.SetPassword "strPassword"
objUser.SetInfo
intRow1 = intRow1 + 1
intRow2 = intRow2 + 1
Loop
 
objExcel.Quit
 
MsgBox "Done"

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yehudahaCommented:
ooops little fix

change line 16

objUser.SetPassword "strPassword"

to this

objUser.SetPassword strPassword
0
 
kjudy408Author Commented:
Getting an error still
Line 16
Char 1
Error: The file name, directory name, or volume label syntax is incorrect.
Code: 8007007B
Source: (null)

My Script:
strComputer = "."
strXlsPath = "C:\0SFTP\test.xls"
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strXlsPath)

intRow1 = 1
intRow2 = 1
 
Do Until objExcel.Cells(intRow1,1).Value = "" Or objExcel.Cells(intRow2,1).Value = ""
strUser = objExcel.Cells(intRow1,1).Value
strPassword = objExcel.Cells(intRow2,2).Value
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", strUser)
objUser.SetPassword strPassword
objUser.SetInfo
intRow1 = intRow1 + 1
intRow2 = intRow2 + 1
Loop

objExcel.Quit

MsgBox "Done"

wscript.quit
0
 
yehudahaCommented:
i think your problem is that the user all ready exist on the computer you running it
i changed the script to echo it.

if i wrong and the user doesn't exist and you still get error let me know.

strComputer = "."
strXlsPath = "C:\0SFTP\test.xls"
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strXlsPath)
 
intRow1 = 1
intRow2 = 1
 
Do Until objExcel.Cells(intRow1,1).Value = "" Or objExcel.Cells(intRow2,1).Value = ""
strUser = objExcel.Cells(intRow1,1).Value
strPassword = objExcel.Cells(intRow2,2).Value
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", strUser)
objUser.SetPassword strPassword
On Error Resume Next
objUser.SetInfo
If Err.Number <> 0 Then
Err.Clear
WScript.Echo strUser & " All Ready Exist On The Target Computer"
Else
On Error Goto 0
End if
intRow1 = intRow1 + 1
intRow2 = intRow2 + 1
Loop
 
objExcel.Quit
 
MsgBox "Done"
 
wscript.quit

Open in new window

0
 
kjudy408Author Commented:
I changed the computername to localhost and ran the script, it created some of the accounts, but many of them it told me they already exist.  However they don't show up in the list of users.
0
 
kjudy408Author Commented:
I don't know if this makes any difference, but I'm running the script in an RDP session.  The machine is a Dell 1950 running Server 2003 SP2, it is part of a domain, but the accounts i need to make are local.
0
 
kjudy408Author Commented:
I found the problem, some of the passwords didn't meet our domain group policy.  I removed that restriction and it created all the other accounts.  Thanks for you help.
0
 
yehudahaCommented:
ok so if the script work and you fixed the problem why close the question and not accepting my answer ?
0
 
kjudy408Author Commented:
Sorry, this is my first post, I thought I did close it and accept your solution.
0
 
yehudahaCommented:
thanks
glad i could help
0
 
yehudahaCommented:
ohh and nice investigation :-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now