Link to home
Start Free TrialLog in
Avatar of tonkajeep34
tonkajeep34Flag for United States of America

asked on

Scripting local User Creation on 2003 server

Hi all,

I use the following dos command to create local users on a win2k3 server for FTP users:

net user userid password  /add  /expires:never /active:yes /passwordreq:no /comment:"Client FTP User"

This works fine for creating the users and saves me a ton of time, however i've noticed one thing. I still have to go into each user and place the check box for "user cannot change password" and "password never expires"

It does take care of the "user must change password at next logon" box.

Any ideas on how to change the above command or can i change the defaults for new user creation?


Thanks,
Tonkajeep34
Avatar of tmack
tmack


try this script...save as USER.VBS and call from command line "cscript.exe USER.VBS"

Const ADS_UF_NORMAL_ACCOUNT = 512
set objParent = GetObject("LDAP://<ParentDN>")
set objUser   = objParent.Create("user", "cn=<UserName>")
objUser.Put "sAMAccountName", "<UserName>"  
objUser.Put "userPrincipalName", "<UserUPN>"
objUser.Put "givenName", "<UserFirstName>"  
objUser.Put "sn", "<UserLastName>"          
objUser.Put "displayName", "<UserFirstName> <UserLastName>"
objUser.Put "pwdLastSet", 0
objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
objUser.SetInfo
objUser.AccountDisabled = FALSE
objUser.SetInfo
Avatar of tonkajeep34

ASKER

Will this work for local users? Can i change ParentDN to the local computer name?
also on the set obj user what needs to be in CN=<??>

Do you know of a good way to create this script from a list of say 100 users? right now i use excel to fill in the fields then copy it to a text doc.

Thanks,
oh..your not using AD??
I am, just not for the FTP users... we're keeping them in a DMZ
im not sure how to do this with local accounts. But you shold be able to select all the accounts at once and select the check box for all the users, right??
Unfortunatly no... it won't let me select multiple users at once...
ASKER CERTIFIED SOLUTION
Avatar of MarinusVD
MarinusVD

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you know after looking that code it becomes so clear...lol...thats should do the trick here..and I learned something as well..
Hmm, i'll give that a try. Does it have to be on serate lines or can it be all on one line? Trying to keep it easy to make the file from a list of users.
Hi,

I just saw your question about the line now.
Why dont you try and write it so that it will read the users from a text file?
I have seen it before somewhere.
Let me know if you want to me to try and dig it out.

Regards
Marinus
If you could find that or point me in that direction it would be very helpful!

Thanks,
Mike
Here you go.
Hope this helps.  now you can make this even better by using CSV's for more fields.  But this one will only work with usernames.

This script will read users from c:\users.txt
Users.txt must have the user names listed one username per row.
eg.
User1
User2

Save below as a vbs file.

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

SourceFile = "c:\users.txt"
Dim ws,f

Set ws = CreateObject ("Scripting.FileSystemObject")
Set f = ws.OpenTextFile (SourceFile, ForReading, True)
Do While f.AtEndOfStream <> True
      If f.AtEndOfStream <> True Then
            Username = f.ReadLine 'set input string to username
            Set oDomain = GetObject("WinNT://computername")    
            Set usr = oDomain.Create("user", ""&username)
            usr.SetPassword "secret***!"
            Usr.Put "PasswordExpired", CLng(1)
            Usr.Put "Description","FTP User"
            usr.SetInfo
      End If
Loop
Awesome. thanks!
No worries!
Hope you get on well.