hey guys,
I've written the script below to add users to a OU in AD. It gets the user names from a txt file.
Everything works great but I can't get the 'password never expires' check box ticked. (bit in red)
Anyone know how??
here's the code..
I've written the script below to add users to a OU in AD. It gets the user names from a txt file.
Everything works great but I can't get the 'password never expires' check box ticked. (bit in red)
Anyone know how??
here's the code..
' create FSO object
Set objfso = CreateObject("Scripting.FileSystemObject")
' open txt file - could be replaced with msgbox for easy one time deal adding
Set objfile = objfso.OpenTextFile("macs.txt", 1)
' Setting constant for password never espire
const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
' cycle though all mac addresses in file doing...
Do Until objfile.AtEndOfStream
' getting single mac address from file
mac = objfile.ReadLine
' setting OU as wireless mac addresses
Set objOU = GetObject("LDAP://OU=Wireless MAC Addresses,dc=domain,dc=com")
' Create user
Set objUser = objOU.Create("User", "cn=" & mac)
' Change names to mac address
objUser.Put "givenName", mac
objUser.Put "sAMAccountName", mac
' adding full logon username
objUser.Put "userPrincipalName", mac & "@domain.com"
' changing so password doesn't have to be changed at next logon
objuser.put "pwdLastSet", -1
' set's user description
objuser.put "Description", "WAN MAC Address for - ** User from old system **"
' allowing user to 'dial in'
objUser.msNPAllowDialin = True
' Setting Values
objUser.SetInfo
' set account password to never expire
intUAC = objUser.Get("userAccountControl")
objUser.Put "userAccountControl", intUAC XOR ADS_UF_DONT_EXPIRE_PASSWD
objUser.SetInfo
' add user to wireless mac addresses group
Set objuser2 = GetObject("LDAP://cn=" & mac & ",OU=Wireless MAC Addresses,dc=domain,dc=com")
Set objgroup = GetObject("LDAP://cn=Wireless MAC Addresses,OU=Basingstoke,OU=Security Groups,OU=Groups,dc=domain,dc=com")
objgroup.add objuser2.ADsPath
' enabling account
intAccValue = 544
objUser.Put "userAccountControl", intAccValue
objUser.SetInfo
' Setting password to be MAC address
objuser.SetPassword mac
objuser.setinfo
Loop
' Closing txt file
objfile.Close
'Quitting
WScript.Quit
Last edited: