Good evening all.
I hate to bother everyone but I'm running into some problems with a VB script I've created to add a user to AD. I'm fairly new to VBScripting and am open to criticism, constructive of otherwise.
Higher up in the script, strLName, strFName, strLoginID, strEndDate & strPasswd are defined based on user input or generated & stored in a variable.
Any assistance is greatly apprecaited. Links on what I need to doublecheck are more than welcome as I'm not looking to be spoonfed.
'
Cheers
I hate to bother everyone but I'm running into some problems with a VB script I've created to add a user to AD. I'm fairly new to VBScripting and am open to criticism, constructive of otherwise.
Higher up in the script, strLName, strFName, strLoginID, strEndDate & strPasswd are defined based on user input or generated & stored in a variable.
Code:
Dim objRootD, strContainer, objOU, oUser
Set objRootD = GetObject("LDAP://bleh.blah.net/OU=Whatever,OU=This Goes On,DC=domain,DC=tld")
Set oUser = objRootD.Create("User", "CN=" & strLName & "\, " & strFName) ' Escape the comma
oUser.Put "sAMAccountName", strLoginID
[!]oUser.SetPassword strPasswd[/!] ' <---First Error Here: Invalid DN syntax Code 80072032
' Tried SetPassword(strPasswd), SetPassword = strPasswd; I even typed in a known/good password, one that would be accepted with no luck
' Regardless of whether or not double quotes are present it still fails.
' I hit up this site of course, [url=http://tinyurl.com/q62zc4][URL unfurl="true"]http://tinyurl.com/q62zc4[/URL][/url], and found lots of info
' However, I couldn't find anything that helped me figure out where I went wrong
' Moving on; I comment out the above line since it doesn't seem to work and I get my...
[!]oUser.SetInfo[/!] ' <--- Second Error Here: General Access Denied Error.
' Adding a user manually via AD Users & Computers works fine so its not an account limitation.
' So this suggest I'm going to need the password line above to work before I can commit my changes.
oUser.Put "givenName", strFName
oUser.Put "AccountExpirationDate", strEndDate ' I assume format is MM/DD/YYYY
oUser.Put "objectClass","top; person; organizationalPerson; user;"
oUser.Put "sn", strLName
oUser.Put "distinguishedName", "CN=" & strLName & "\, " & strFName & ",OU=Whatever,OU=This Goes On,DC=domain,DC=tld"
oUser.Put "displayName", strLName & ", " & strFName
oUser.Put "name", strLName & ", " & strFName
oUser.Put "primaryGroupID", "999"
oUser.Put "sAMAccountType", "805306368"
oUser.Put "userPrincipalName", strLoginID & "@domain.tld"
oUser.Put "objectCategory", "CN=Person,CN=Schema,CN=Configuration,DC=domain,DC=tld"
oUser.SetInfo
Any assistance is greatly apprecaited. Links on what I need to doublecheck are more than welcome as I'm not looking to be spoonfed.
'
Cheers