Monday, October 29, 2007

Creating user accounts on your W2K8 core

Again, since there is no GUI available, you'll have to compile a script to create your user accounts.
There are 3 possible ways of creating user accounts on your W2K8 core: create a vbs scripts, or use the DSADD or csv command line possibilities.

To create a vbs script, log on to your server and create a vbs file where you would like it with the command: edit c:\temp\user.vbs. In this case, I'll create a user.vbs file in my temp folder.
Then, we'll have to use our scripting knowledge to create the user and their desired attributes. I'm not going to elaborate on all the options, since there are too many, but here is the standard example which you can adjust to your needs:
Set objOU = GetObject("LDAP://OU=Users,OU=_Test,dc=fabrikam,dc=com")
Set objUser = objOU.Create("User", "cn=Kristof Vanweert")
objUser.Put "sAMAccountName", "KrVa"
objUser.SetInfo

Also, Microsoft provides a site on which you have a ton of script examples you can use to extract information: The Script Center Script Repository

CSV files are saved in a csv format, so to create one, we can enter edit c:\temp\user.csv. In the blue screen you receive you can enter again the information you want, for example:
DN,objectClass,sAMAccountName,sn,givenName,userPrincipalName
"CN=Kristof Vanweert,OU=Users,OU=_Test,DC=vm,DC=local", user,KrVa,Vanweert,Kristof,kristof.vanweert@vm.local

Notice that the first line declares all the variables that have to come back on every user you create below. Also, these variables are the same you can use in a vbs script.
When your file is finished, you can import it with the command: csvde -i -f c:\temp\user.csv. A list with all options you can add to the csvde command, you can find here.

Last, and probably easiest to work with, is the DSADD command. It features all the most important attributes, but not everything can be done with this command.
Users created with this command are saved in a cmd file: edit edit c:\temp\user.cmd which is later simply executed from the command line. In the command below, I create my user account in the correct OU and set a temporary password:
dsadd user "CN=Kristof Vanweert,OU=Users,OU=_Test,DC=vm,DC=local" -samid KrVa -upn KrVa -fn Kristof -mi THJ -ln Vanweert -display "Kristof Vanweert" -pwd Azerty123 -mustchpwd yes -pwdneverexpires yes
Again, a whole list of switches you can use, can be found at microsoft.

Of course, it is pretty obvious these commands can be adjusted to create OU's, groups, computers, ... Also modifying, deleting, retrieving information, ... can be done by changing a few parameters in the sample scripts posted above.

Have fun

2 comments:

CresceNet said...

Gostei muito desse post e seu blog é muito interessante, vou passar por aqui sempre =) Depois dá uma passada lá no meu site, que é sobre o CresceNet, espero que goste. O endereço dele é http://www.provedorcrescenet.com . Um abraço.

muhazir said...

using command line like DOS, make me crazy, but it is look easy.
mr., do you have e-book about w2k8 core Active directory
thanks alot