Advertisement

06.06.2007 at 02:23AM PDT, ID: 22615831
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

VBscript for creating Active Directory users - user accounts expired!!

Tags: vbscript, directory, active, user
I have created a VB script to create numerous users in a Windows 2000 Active Dicretory domain reading the usernames from a text file in the format

firstname lastname

The script creates the users, maps home directory, enables account, sets password

however when any try to log on they get the message:

"your account has expired"

The accoutn properties are the same as the existing accounts when i check them manually - they are enabled, they havent expired, etc can someone tell me where i am going wrong as its driving me crazy!

Script below:

On Error Resume Next  
Password = "password"              
usrfile = "usernames.txt"  
dcroot = "ou=test users,dc=testdomain,dc=COM"
hdrive = "H:"
bat = "login.bat"
hdirectory = "\\Server\users\%username%"
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(usrfile) Then
    Set objFile = objFSO.OpenTextFile(usrfile, 1)
Else
    Wscript.Echo "File" & usrfile & " does not exist."
    WScript.Quit
End If

WScript.Echo "Reading user names from " & usrfile & VbCrLf
WScript.Echo "Line number:" & VbTab & "Action:"
WScript.Echo "========================================================================="
Do Until objFile.AtEndOfStream
    CurLine = objFile.Line
    Userline = objFile.ReadLine
    If not Userline = "" Then
       useNames = Split(Userline, " ")
          FirstName = useNames(0)
          Length = UBound(useNames)
     If Length > 1 Then
          LastName  = useNames(1) & " " & useNames(2)
     Else        
          LastName  = useNames(1)
     End If
          FullName = useNames(0) & " " & LastName
          FirstInitial = left(FirstName, 1)
          LName = useNames(Length)
          LogonName = LName & FirstInitial
          Userpn = LogonName & "@testdomain.COM"
        Set objContainer = GetObject("LDAP://" & dcroot)
        If Err <> 0 Then
            WScript.Echo "Can not bind to " & dcroot & ". Check syntax."
            WScript.Quit
        End If
        Err.Clear
           
            Set objNew = objContainer.Create("User", "cn=" & FullName)
            objNew.Put "sAMAccountName", LogonName
            objNew.Put "UserPrincipalName", Userpn
            objNew.Put "givenName", FirstName
            objNew.Put "sn", LastName
            objNew.Put "displayName", FirstName & " " & LastName
            objNew.Put "homeDrive", hdrive
            objNew.Put "homeDirectory", hdirectory
            objNew.Put "scriptPath", bat
            objNew.SetInfo
            Set objNew = Nothing
            Set objUser = GetObject("LDAP://cn=" & _
                          FullName & "," & dcroot)
            objUser.ChangePassword "", Password
            objUser.SetInfo
            objUser.AccountDisabled = FALSE
            objUser.SetInfo
            objUser.AccountExpires = -1
            objUser.SetInfo
            intUAC = objUser.Get("userAccountControl")
            objUser.Put "userAccountControl", intUAC XOR _
            ADS_UF_DONT_EXPIRE_PASSWD
            objUser.SetInfo
            Set grp = GetObject("LDAP://cn=test group,ou=testusers,dc=testdomain,dc=COM")
            grp.Add(objUser.AdsPath)
            grp.SetInfo
            Set objUser = Nothing
            Set grp = Nothing
            WScript.Echo CurLine & vbTab & vbTab & "User """ & _
                         FullName & """ (" & LogonName & " , " & Userpn &  ") created. " & pwderr
       
    Else
        WScript.Echo CurLine & vbTab & vbTab & _
                     "Skipping Empty line in " & usrfile
    End If
Loop
objFile.Close


Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: mistaj
Solution Provided By: mistaj
Participating Experts: 1
Solution Grade: A
Views: 257
Translate:
Loading Advertisement...
06.06.2007 at 02:36AM PDT, ID: 19223682

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.06.2007 at 03:48AM PDT, ID: 19223951

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.06.2007 at 02:32PM PDT, ID: 19228744

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.06.2007 at 02:36PM PDT, ID: 19228770

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
10.29.2007 at 05:27PM PDT, ID: 20174177

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29