More Scripting Help - Creating AD Users with Email

Hey,
I am a bit lost here.  I am writing a script to add a user to AD.  Here is what I have.
________________________________________________
dim strDomainName, InputOU, InputUN, InputSN, InputDN, InputDsc, objOu, objUser, InputGrp, objGroup, InputGrpOu

InputOU = InputBox("Enter OU")
InputUN = InputBox("Enter User Name")
InputGiven = InputBox("Enter First Name")
InputSN = Inputbox("Enter Last Name")
InputDsc = InputBox("Enter Description")
InputGrp = InputBox("Enter Group")
InputGrpOU = "CN=Users"            'InputBox ("Enter OU of Group")
Set objOU = GetObject("LDAP://ou=" & InputOU & ",dc=JSC,dc=com")

Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.Put "userPrincipalName", InputUN
objUser.Put "sAMAccountName", InputUN
objUser.Put "givenName", InputGiven
objUser.Put "sn", InputSN
objUser.Put "displayName", InputGiven & " " & InputSN
objUser.Put "Description", InputDsc
objUser.SetInfo
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False

'Add to group
Set objGroup = GetObject("LDAP://CN=" & InputGrp & "," & InputGrpOU & ",dc=JSC,dc=com")
objGroup.add(objUser.ADsPath)
____________________________________________________________

My user is being created in the correct place.  But shows up disabled.  I also do not know how to add an email address for him in my domain.
LVL 1
jsctechyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Your .setinfo needs to be the 'last' item when updating the properties - else those are missed...

You have:
objUser.SetInfo
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False

it should be:
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False
objUser.SetInfo

You can add the mail info using:
objUser.mail=objUser.SamAccountName & "@domain.com" 'remember to use SetInfo
0
jsctechyAuthor Commented:
I get an error that way.

Line 19 Chr 1
objUser.SetPassword "TESTPW" 'meets pw req
0
sirbountyCommented:
What's the error?
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

jsctechyAuthor Commented:
Line: 19
Chr:  1
Error:  There is no such object on the server.
Code: 80072030
Source: (null)

Seems as when trying to set the PW, the object doesn't exist yet.
0
sirbountyCommented:
Ah - you can use a couple of SetInfo's for that...


Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.SetInfo
objUser.Put "userPrincipalName", InputUN
objUser.Put "sAMAccountName", InputUN
objUser.Put "givenName", InputGiven
objUser.Put "sn", InputSN
objUser.Put "displayName", InputGiven & " " & InputSN
objUser.Put "Description", InputDsc
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False
objUser.SetInfo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jsctechyAuthor Commented:
hey- I did it the original way I posted, but at the end of the setpassword and accountdisabled, I setinfo again
0
jsctechyAuthor Commented:
Cool- Thanks.
So for email, I can just do this
objUser.mail=objUser.SamAccountName & "@JSC.com"
0
sirbountyCommented:
Yep yep...
Cool. :^)
0
jsctechyAuthor Commented:
Thanks.  I will try that.
0
sirbountyCommented:
Good luck! :^)
0
jsctechyAuthor Commented:
Hey,
1 Q-
If I use  -    objUser.mail=objUser.SamAccountName & "@JSC.com"
Does that create the mailbox on the exchange server, or just add an email in the email address field?
I want it to create the mailbox, same as when I manually create a user.  After specifying a password, the next screen will be to create an email box (checkbox), with also Server and Mailbox Store options.
0
sirbountyCommented:
That, I've never done (the above only adds the mail property)...however according to this site, it seems to be fairly simple:

http://techtasks.com/code/viewbookcode/1237

Try adding:

objUser.CreateMailbox objUser.adsPath

to the end of the script.

http://searchvb.techtarget.com/tip/0,289483,sid8_gci1086268,00.html gives another good example.
0
jsctechyAuthor Commented:
I am confused....
Should I do something like this?

Dim oIADSUser
Dim MStore
strDefaultNC = "DC=EnterYourDomainName,DC=com"
Set oIADSUser = GetObject("LDAP://CN=" & InputUN & "," & "OU=" & InputOU & "," & "DC=JSC,DC=com")

oIADSUser.CreateMailbox "LDAP://CN=First Storage Group,
CN=InformationStore,
CN=JSCEMAIL,
CN=Servers,
CN=First Administrative Group,
CN=Administrative Groups,
CN=EnterYourSMTPOrganisationName, -????????
CN=Microsoft Exchange,
CN=Services,
CN=Configuration,
DC=JSC,DC=com"
oIADSUser.SetInfo

0
jsctechyAuthor Commented:
unsure how to get the full DN for the exchange server info.
Right now I am trying from command prompt to get the info-
CMD>ldifde -d cn=existinguser,ou=someou,dc=domain,dc=root -f con
0
sirbountyCommented:
Again, Im not really familiar with the Exchange piece of this, but I was thinking it would be:

Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.SetInfo
objUser.Put "userPrincipalName", InputUN
objUser.Put "sAMAccountName", InputUN
objUser.Put "givenName", InputGiven
objUser.Put "sn", InputSN
objUser.Put "displayName", InputGiven & " " & InputSN
objUser.Put "Description", InputDsc
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False
objUser.CreateMailbox objUser.adsPath 'does this work?
objUser.SetInfo
0
jsctechyAuthor Commented:
I think I got it.....

homeMDB:
 CN=Mailbox Store (JSEMAIL),CN=First Storage Group,CN=InformationStore,CN=JSEMAIL,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=JSC,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=JSC,DC=com
0
sirbountyCommented:
Or what about:

Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.SetInfo
objUser.Put "userPrincipalName", InputUN
objUser.Put "sAMAccountName", InputUN
objUser.Put "givenName", InputGiven
objUser.Put "sn", InputSN
objUser.Put "displayName", InputGiven & " " & InputSN
objUser.Put "Description", InputDsc
objUser.SetPassword "TESTPW"
objUser.AccountDisabled = False
objUser.CreateMailbox objUser.DN 'does this work?
objUser.SetInfo
0
jsctechyAuthor Commented:
Hi,
No-
objUser.CreateMailbox is not supported...?  This is for Exchange 2003 on a 2000 Domain
0
sirbountyCommented:
According to this it is - but perhaps the reference was setup incorrectly..
http://www.msexchange.org/articles/Scripting-Exchange-VBScript-ADSI-Part2.html

Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.SetInfo
'[...]
objUser.AccountDisabled = False
objUser.CreateMailbox objUser.DN 'does this work?
objUser.SetInfo
'adding this...of course, I don't know what these settings are though...
'  would've though simply using the DN to the newly created user would do it?
Set objMailbox = objUser
  objMailbox.CreateMailbox "LDAP://CN=" & MDBName & _
                               ",CN=" & StorageGroup & _
                               ",CN=InformationStore" & _
                               ",CN=" & Server & _
                               ",CN=Servers" & _
                               ",CN=" & AdminGroup & _
                               ",CN=Administrative Groups" & _
                               ",CN=" & Organization & _
                               ",CN=Microsoft Exchange,CN=Services" & _
                               ",CN=Configuration," & DomainDN
objUser.SetInfo
0
jsctechyAuthor Commented:
getting an error on this:

Set objMailbox = objUser
0
sirbountyCommented:
Unfortunately, I don't have a test domain to try this out on...
I'm just not sure what to do from here as I've not worked with creating mailboxes before...sorry.
0
jsctechyAuthor Commented:
Here is what I have right now
____________________________

dim strDomainName, InputOU, InputUN, InputSN, InputDN, InputDsc, objOu, objUser, InputGrp, objGroup, InputGrpOu, strHomeMDB, objMailbox

InputOU = InputBox("Enter OU")
InputUN = InputBox("Enter User Name")
InputGiven = InputBox("Enter First Name")
InputSN = Inputbox("Enter Last Name")
InputDsc = InputBox("Enter Description")
InputGrp = InputBox("Enter Group")
InputGrpOU = "CN=Users"            'InputBox ("Enter OU of Group")
Set objOU = GetObject("LDAP://ou=" & InputOU & ",dc=JSC,dc=com")
'Set objMailbox = objUser
strHomeMDB = "CN=Mailbox Store (JSEMAIL),CN=First Storage Group,CN=InformationStore,CN=JSEMAIL,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=JSINC,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=JSC,DC=com"
Set objUser = objOU.Create("User", "cn=" & InputGiven & " " & InputSN)
objUser.Put "userPrincipalName", InputUN
objUser.Put "sAMAccountName", InputUN
objUser.Put "givenName", InputGiven
objUser.Put "sn", InputSN
objUser.Put "displayName", InputGiven & " " & InputSN
objUser.Put "Description", InputDsc
objUser.SetInfo
objUser.SetPassword "arkansas"
objUser.AccountDisabled = False
objUser.Put "physicalDeliveryOfficeName", InputOU
objUser.Put "homeDirectory", "\\Jsfile\%username%"
objUser.Put "homedrive", "H:"
objUser.Put "ScriptPath", "logon.cmd"
objUser.SetInfo
'create mailbox
objUser.CreateMailBox "LDAP://" & strHomeMDB
objUser.SetInfo

'Add to group
Set objGroup = GetObject("LDAP://CN=" & InputGrp & "," & InputGrpOU & ",dc=JSC,dc=com")
objGroup.add(objUser.ADsPath)
____________________________
0
jsctechyAuthor Commented:
Oh- maybe someone else will answer.  I am searching online and find stuff that doesn't seem to work w/ my Exchange/AD versions.
0
jsctechyAuthor Commented:
Figured it out.....!  Finally
_____________________________
strHomeMDB = "CN=Mailbox Store (JSEMAIL),CN=First Storage Group,CN=InformationStore,CN=JSEMAIL,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=JSCINC,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=JSC,DC=com"
'create mailbox
objUser.Put "msExchHomeServerName", "/o=JSINC/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=JSEMAIL"
objUser.Put "mailNickname", InputUN
objUser.Put "mail", InputUN & "@JSC.com"
objUser.Put "homeMDB", strHomeMDB
objUser.Put "mDBUseDefaults", True
objUser.SetInfo
________________________________________
0
sirbountyCommented:
Awesome!
Glad you got it sorted. :^)
0
jsctechyAuthor Commented:
Thanks- points go to you (obviously) for the reason I started to post.

Thanks again- will be posting more shortly :)
0
sirbountyCommented:
Thanx! :
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.